Forum Discussion

tgunasek's avatar
tgunasek
New Contributor
7 years ago

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

  • PaulMS's avatar
    PaulMS
    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.

    • tgunasek's avatar
      tgunasek
      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

       

      • tgunasek's avatar
        tgunasek
        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}