AgileApps Support Wiki Pre Release

Difference between revisions of "Specifying Query Parameters in REST APIs"

From AgileApps Support Wiki
imported>Aeric
imported>Aeric
m (Text replace - '{domain}' to '{{domain}}')
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Specifying Request Arguments ==
In a REST GET request, you can specify arguments and the response format in the URL. For other request types, you can specify the response format.
In a REST request, you pass arguments in the form of ''query parameters''. Those parameters are specified in the form <tt>parameterName=value</tt>.
__TOC__
 
A ''parameter list'' is appended to a URI after a "?". Multiple parameters are separated by "&", as shown here:
:<syntaxhighlight lang="vbnet">
  http://{domain}/{address}?parameterName1=value1&parameterName2=value2
</syntaxhighlight>
 
For example:
:<syntaxhighlight lang="vbnet">
  http://myLongJump.com/networking/rest/user?fieldList=*&sortBy=first_name
</syntaxhighlight>
 
For boolean arguments, the value passed can be "1" or "true", "0" or "false".
 
In some cases, it may be necessary to [http://www.blooberry.com/indexdot/html/topics/urlencoding.htm encode special characters] in order to include them in an argument value. For example:
:{|
! Instead of !! Use
|-
| & (A&B) || %26 (A%26B)
|-
| space (A B) || %32 (A%32B)
|}
 
== Specifying Response Format ==
== Specifying Response Format ==
You specify the response format as either [http://en.wikipedia.org/wiki/XML XML] (the default) or [http://en.wikipedia.org/wiki/Json JSON], using the <tt>alt</tt> parameter:
You specify the response format as either [http://en.wikipedia.org/wiki/XML XML] (the default) or [http://en.wikipedia.org/wiki/Json JSON], using the <tt>alt</tt> parameter:
Line 30: Line 8:
;Example:  
;Example:  
:<syntaxhighlight lang="vbnet">
:<syntaxhighlight lang="vbnet">
   http://{domain}/{address}?alt=json
   https://{{domain}}/networking/{targetAddress}?alt=json
</syntaxhighlight>
</syntaxhighlight>
== Specifying Request Arguments ==
{{:Specifying Parameters in a URL}}

Latest revision as of 19:21, 25 April 2014

In a REST GET request, you can specify arguments and the response format in the URL. For other request types, you can specify the response format.

Specifying Response Format

You specify the response format as either XML (the default) or JSON, using the alt parameter:

  • ?alt=xml
  • ?alt=json
Example
<syntaxhighlight lang="vbnet">
 https://{yourDomain}/networking/{targetAddress}?alt=json

</syntaxhighlight>

Specifying Request Arguments

You pass arguments in a URL using query parameters. Those parameters are specified in the form parameterName=value.

A parameter list is appended to a URI after a "?". Multiple parameters are separated by "&", as shown here:

<syntaxhighlight lang="vbnet">
 https://{yourDomain}/networking/{targetAddress}?parameterName1=value1&parameterName2=value2

</syntaxhighlight>

For boolean arguments, the value passed can be "1" or "true", "0" or "false".

Notepad.png

Note:
When specifying a URL in code, any special characters (characters other than letters and numbers) need to be encoded. For example, a space character can be encoded using either + or %20.

(Browsers typically take care of encoding URLs entered into the address bar--so the URL displayed after visiting a page may differ somewhat from the one that was initially entered.)

Here are some typical encodings:

space
+
%
%20 or +
%2B
%25

So:

Instead of Use

& (A&B)
space (A B)

%26 (A%26B)
%20 (A%20B)


It can be hard to get be hard to get the encoding right, so it's desirable to use a language library designed for the purpose.
Learn more: