cancel
Showing results for 
Search instead for 
Did you mean: 

How to set the Request Header for a REST service

Highlighted
New Contributor

How to set the Request Header for a REST service

I need some clarity on how to correctly set request header attributes in ReadyAPI - SOAP UI Pro, and am hoping someone on this forum is able to help.

 

As I am very new to the ReadyAPI tool, I was looking at the ReadyAPI documentation.

 

I see that there is a REST Parameter Style called "HEADER" which can be selected when adding/setting parameters under the REQUEST parameters table (vertical tab) for the service. But in addition to this there is also a "Headers Panel" at the bottom of the screen (horizontal tab just after the Auth tab) where you appear to be able to add header values as key/value pairs.

 

Can someone clarify what the difference is between these two, and which should be used to set request header attributes?

 

The REST service I am attempting to test, requires a fixed apitoken value to be set in the header, and it's currently unclear to me how this should be set in the ReadyAPI interface.

 

Any assistance would be appreciated.

6 REPLIES 6
Highlighted
Super Contributor

If a header (like the token) is required with all requests for a resource/method then the header parameters should be added at that resource/method level. When any new request is created the parameter will be added with the default value so there is less chance of missing or incorrect parameters.

 

 

The default value for the parameter can be changed or left blank in each request test step if necessary.

 

If a header is only required for one specific request then it can be added on the headers (horizontal tab) without changing any other requests.

Highlighted
New Contributor

Many thanks for the clarification around the header. Just curious about the other horizontal panels such as "Auth", given that you have mentioned the Horizontal Request panel only applies to individual requests. Does that mean Authentication configured through that tab would only apply to a individual request, and that you could have different authentication configurations for different requests within a individual REST service project in ReadyAPI?

 

This next question isn't really around the header, but as it's related to one of the REST service API methods I'm attempting to test, I'm raising it under this topic. This is the JSON request code snippet which I've been given to try & simulate/setup in ReadyAPI.

 

*******************************
HEADERS = {'apitoken': XXXX}

resp = requests.post(
        url= 'https://xxxx.xxxxxxx.com/rest/xxxx/search'
        data={'name': nameArg, 'country': countryArg},
        headers=HEADERS
    )
*******************************

 

Would you be able to confirm if this is the correct way to set it up in ReadyAPI? A JSON (not XML) request and response would be required here. The associated screenshot is attached.

 

Method = POST

Endpoint = https://xxxx.xxxxxxx.com

Resource = /rest/xxxx/search

Vertical Request Parameters tab line items:

Name: name, Value: nameArg, Style: QUERY, Level: METHOD

Name: country, Value: countryArg, Style: QUERY, Level: METHOD

Name: apitoken, Value:  XXXX, Style: HEADER, Level: RESOURCE

 

MediaType = application/json

 

Highlighted
New Contributor

Having read through some further ReadyAPI Documentation, I see that the text area below the Media Type (application/json) dropdown is called the "Content Editor".

 

Is this where the json request body arguments should be set? I.e. rather than as request parameters under the Parameter editor?

 

HEADERS = {'apitoken': XXXX}

resp = requests.post(
        url= 'https://xxxx.xxxxxxx.com/rest/xxxx/search'
        data={'name': nameArg, 'country': countryArg},
        headers=HEADERS
    )

 

I.e. for the JSON example I am trying to simulate/test (above) in ReadyAPI, should I be entering the following under the "Content Editor", instead of adding them as request parameters?

 

{'name': NameArg, 'country': CountryArg}

Highlighted
Contributor

"is this where the json request body arguments should be set?"

 

Yes - at least that's how it works for me. [ edited] - for clarity for any POST method that has a lot of name/value pairs I use the JSON form for clarity and ease and use that editor window below "Media Type" to put my JSON. I don't do headers in that space.

Highlighted
Super Contributor

Yes it seems that the name/country data would be included in the content editor so you don't need name/country parameters.

There is a JSON request example in https://support.smartbear.com/readyapi/docs/projects/ui/request/request/vertical/rest.html

 

The Raw panel is also useful to see the actual request that was sent

https://support.smartbear.com/readyapi/docs/projects/ui/request/request/vertical/raw.html

 

Authorization can be different for any request

https://support.smartbear.com/readyapi/docs/projects/requests/auth/index.html

Highlighted
New Contributor

Thank you both for your comments. I found the RAW panel to be quite useful while testing.

 

I've now managed to setup and test the two REST services with a JSON Request, returning a JSON Response.

 

New Here?
Join us and watch the welcome video:
Announcements
TechCorner Leaderboard
Want a fun and easy way to learn ReadyAPI and show off your skills? Try solving weekly TechCorner challenges and get into the Leaderboard!


Challenge Status

Get a full Raw JMS request

Participate!

Compare an expected JSON value and actual response in Events

Participate!

Fetch value/data from JSON response using Groovy Script

See replies!

Get data from Petstore and add it to Excel sheets

Participate!
Top Kudoed Authors