Forum Discussion

maxrussell's avatar
maxrussell
Contributor
4 years ago
Solved

Adding a default argument to requests

We are currently using a parameter $format. The default is to specify returning JSON. This can be left empty.

If we want to add a notification to server to use a redirect, we have to add this to the $format parameter, but specifically after the JSON entry, which must be placed at start of string.

 

Is it possible to :

  • create a parameter at a project level which can be applied to all requests
  • can this be selected to use/not use as desired
  • richie's avatar
    richie
    4 years ago
    Hey maxrussell

    Yep the redirect query parm can also be setup as a project level property but theres a couple of things you need to be aware of.

    Query parms can br in any order....the endpoint doesnt care what sequence the query parms are in (i'll come back to this point).

    Can you confirm both the $format and $redirect query parms are always present what ever values they hold? That is, the presence of a query parameter is notswitcheable between test cases. You can set the parm to PLAIN (from QUERY to PLAIN) either at resource or method level and this will result in that query parm not appearing in the associTed teststeps that use request thats been setup. However, this will effect all teststeps that use this request within the project.

    To explain setting a parm to PLAIN If your URI query parms are as follows:
    ?$format=XML&$redirect

    Then $format is set as QUERY and $redirect is set as QUERY.

    If $redirect was set as PLAIN, your query parms in your URI would look like:
    ?$format=XML

    So. Can you confirm that the $redirect parm label is always present in your request?

    Can you confirm what values the $redirect parameter has?

    If you have an empty query parm e.g. as $format parm appears in the following example

    ?$format=&$redirect=yes

    Then the empty $format parm needs to go anywhere but the last parameter in the sequence. I cant quite remember but i think empty parms CANNOT be the last parm in the list. Trial and error will prove this out...im 95% positive about that.

    Typically you can store ANY REST parameter (URI or QUERY or MATRIX or HEADER) as properties which can be either project or testsuite or testcase or even at properties teststep level

    Ta

    Rich

8 Replies

  • richie's avatar
    richie
    Community Hero
    Hey maxrussell,

    I dont really understand any of the first paragraph im afraid, can you clarify/pad out/add more detail please? You mention you have a $format parm....is this uri/template/resource parm or query parm or matrix parm or header parm?

    I think you indicate the $format parm (whatever type it is) can be empty (no value)....is that correct?

    Next i think you indicate if you want a redirect you have to specify some value in the $format parm....but you state "specifically after the json entry at the start of the string" i have no idea what youre talking about here. Can you rephrase this completely?

    You mention json...do you mean a payload in the request or response?

    In answer to your 2 bullet points the answer is "yes" on both counts.

    Cheers

    Rich
    • maxrussell's avatar
      maxrussell
      Contributor

      Yes - so -

       

      in the test request to our particular endpoint, there is a parameter $format which specifies response type. Default response type is JSON. This is optional to send in the $format request, but it is required when adding the additional redirect portion to the $format string - e.g. JSON&$redirect

      • richie's avatar
        richie
        Community Hero
        Hey maxrussell,

        Sorry, are you saying you have a $format parameter that specifies response type...do you mean datatype so the Content-Type header on your response is 'application/json'?

        Is the parameter a query or uri or header parameter?

        Is there a reason youre using a $format to specify datatype of response cos the standard HTTP header 'Accept' does this already? (Accept header defines the datatype of the response)

        Is the $redirect another uri or query parameter? The way youve written it below it appears as though that redirect is a query parameter....

        Im typing this out on my phone (sp i cant see your original post details whilst responding to your last message), but the standard REST parameters (uri, query, matrix and header) all can be set using variable values (entitled properties in ReadyAPI!/SoapUI) rather than hardcoded values. Is that what you want to do?

        Can you please supply the full URI (NOT the full URL) with all parameters to provide a better understanding of your APIs request please? To cover off security considerations dont include the host/ip address or the username/password in your response, but you can provide the full URI without breaking any of your company's security rules.

        Ta

        Rich