REST.get: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 15: Line 15:
{{param|getFullResponse|Boolean (0:1) to get full response.}}
{{param|getFullResponse|Boolean (0:1) to get full response.}}
'''Returns'''
'''Returns'''
HTTP response as JSON (if full response) or server response, usually JSON but can be XML, HTML, or other formats.
HTTP response as JSON (if full response) or server response, usually JSON but can be XML, HTML, or other formats.




|example=
|example=
TEXT HERE
Get the specified user.
<source lang="mtmacro" line>
<source lang="mtmacro" line>
TEXT HERE
[h: baseURL = "https://reqres.in"]
[h: path = "/api/users/2"]
 
[h: response = REST.get(baseURL + path, 0)]
 
<br>
Response: [r: baseURL + path]
<pre>
[r: json.indent(response, 2)]
</pre>
 
<br><br>
 
[h: response = REST.get(baseURL + path, 1)]
 
<br>
Full Response: [r: baseURL + path]
<pre>
[r: json.indent(response, 2)]
</pre>
</source>
</source>
Returns:
Returns:

Revision as of 04:24, 16 March 2019

REST.get() Function

 Note: This function can only be used in a Trusted Macro

Introduced in version 1.5
Perform an HTTP get request to the specified URL to retrieve a resource or information.

Usage

REST.get(url, getFullResponse)

Parameters

  • url -
  • getFullResponse - Boolean (0:1) to get full response.

Returns

HTTP response as JSON (if full response) or server response, usually JSON but can be XML, HTML, or other formats.

Example

Get the specified user.
[h: baseURL = "https://reqres.in"]
[h: path = "/api/users/2"]

[h: response = REST.get(baseURL + path, 0)]

<br>
Response: [r: baseURL + path]
<pre>
[r: json.indent(response, 2)]
</pre>

<br><br>

[h: response = REST.get(baseURL + path, 1)]

<br>
Full Response: [r: baseURL + path]
<pre>
[r: json.indent(response, 2)]
</pre>

Returns:

TEXT HERE

See Also

Version Changes

  • 1.5 - Added to main MapTool build.