cancel
Showing results for 
Search instead for 
Did you mean: 

Adding a default argument to requests

Contributor

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
8 REPLIES 8
Community Hero

Re: Adding a default argument to requests

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
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Contributor

Re: Adding a default argument to requests

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

Community Hero

Re: Adding a default argument to requests

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
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Contributor

Re: Adding a default argument to requests

 Yes - we can request Application/JSON or XML

 

for an example of a GET to a Resource -

/rest/data/beta/ourendpoint/views

 

and currently using parameters to send up the redirect (this was to test using specifically we can redirect via a parameter. in the call)

?$format=&$streamRedirectOptIn

 

where we specifically want the XML format and redirect, that parameter becomes

?$format=XML&$streamRedirectOptIn

 

that's what we need to send up to use the optional format and the optional redirect.

 

Currently, I'm setting that ?$format=&$streamRedirectOptIn in that format parameter, against each test. I'd just like to have a project level parameter that I can apply.

 

 

Community Hero

Re: Adding a default argument to requests

Hey @maxrussell,

Ok we're almost there. Just to clarify about parameters in REST

REST has 4 different parameter types:

1. Uri also called path also called resource parameters
2. Query parameters
3. Matrix parameters
4. Header parameters

Example URI:

/home/dev/{URI_parm1}/resource?query_parm1={qparm1_value}&query_parm2={qparm2_value}

So the URI would appear as:

/home/dev/{URI_parm1}/resource?query_parm1=json&query_parm2=40

(Note: the theory indicates matrix parameters are almost the same as query parms except instead of using the & symbol to separate the parameters, instead ; chars are used. Ive never tested a system with matrix parms but i thought id include it for completeness)

Im explaining the above so you can try and answer my questions.

SO! query parameters (which is what you appear to be talking about) has the pattern:

?parm1=parm2_value1&parm2=parm2_value2

Youre talking about using the following:

?$format=&$streamRedirectOptIn

And

?$format=XML&$streamRedirectOptIn

So using your example, yo7 have 2 query parameters. The query parm name labels are $format and $streamRedirectOptIn

So your $format query parameter can have no value (which results in json being returned in the response's payload). OR, the $format query parameter can have the value XML.

The $streamRedirectOptIn query parameter doesnt appear to have a value. Does this mean this query parm can be empty and so redirect doesnt happen? I.e. does this query parm always have to be specified, but can be empty (if no redirect) and if value is present thats the url you redirect to?

If you can answer the above, this will help me answer what you need but without knowing anything else its quite easy to setup your parm so that they source from project or test suite or testcase or even properties step level properties.

To setup your $format parm to reference XML as a project level property you would add a custom level project property with label 'type' and value 'XML' and in your request you woulf specify the $format query parm value as ${#Project#type}

Your $format parm would be populated with value XML when the request was submitted.

Btw, setting all this stuff up can be made a lot easier if you using readyapis/soapuis functionality to create a project. What was the mechanism you used to create your project?

Cheers

Rich


if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Contributor

Re: Adding a default argument to requests

the redirect request is a query parameter.

 

the format parameter can have no value, JSON, or XML. No value is a default to JSON.

 

Is the redirect then also possible to be setup as a custom project level property?

 

All tests were built in ReadyAPI from our imported swagger json.

Community Hero

Re: Adding a default argument to requests

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
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Community Manager

Re: Adding a default argument to requests

Thank you, Richie!

 

@maxrussell were you able to solve this? Please share the solution with us!


Sonya Mihaljova
Community and Education Specialist

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors