REST.get: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
No edit summary
m (Taustin moved page rEST.get to REST.get)
 
(13 intermediate revisions by 4 users not shown)
Line 2: Line 2:
|name=REST.get
|name=REST.get
|trusted=true
|trusted=true
|version=1.5
|version=1.5.0
|description=
|description=
Get...
Perform an HTTP get request to the specified URL to retrieve a resource or information.


|usage=
|usage=
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
REST.get(url)
REST.get(url, getFullResponse)
REST.get(url, getFullResponse)
</source>
REST.get(url, headers, getFullResponse)
</syntaxhighlight>


'''Parameters'''
'''Parameters'''
{{param|url|}}
{{param|url|String containing the URL to the resource or collection of resources.}}
{{param|getFullResponse|Boolean (0:1) to get full response.}}
{{param|getFullResponse|Boolean (0:1). Optional.  Set true(1) to get full response.}}
{{param|headers|JSON object. Optional JSON headers.}}
'''Returns'''
'''Returns'''
Response as a JSON object.
 
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>
<syntaxhighlight lang="mtmacro" line>
</source>
[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>
</syntaxhighlight>
Returns:
Returns:
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
TEXT HERE
 
</source>
Response: https://reqres.in/api/users/2
{"data": {
  "id": 2,
  "first_name": "Janet",
  "last_name": "Weaver",
  "avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/josephstein/128.jpg"
}}
 
 
Full Response: https://reqres.in/api/users/2
{
  "status": 200,
  "headers":  {
    "access-control-allow-origin": ["*"],
    "cf-ray": ["4b9244475b1b5432-LAX"],
    "content-type": ["application/json; charset=utf-8"],
    "date": ["Sun, 17 Mar 2019 22:05:09 GMT"],
    "etag": ["W/\"89-bSBFK27ZbQL+K8fMuJn/jZrcUuk\""],
    "expect-ct": ["max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\""],
    "server": ["cloudflare"],
    "set-cookie": ["__cfduid=d5f84a1d88f4b568cd9547d6f76b1712b1552860309; expires=Mon, 16-Mar-20 22:05:09 GMT; path=/; domain=.reqres.in; HttpOnly"],
    "x-powered-by": ["Express"]
  },
  "body": {"data":  {
    "id": 2,
    "first_name": "Janet",
    "last_name": "Weaver",
    "avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/josephstein/128.jpg"
  }}
}</syntaxhighlight>
 
'''Simple Syrinscape Example'''
 
[https://forum.syrinscape.com/t/how-to-use-online-player-with-maptool/6789 From the Syrinscape forums].
<syntaxhighlight lang="mtmacro" line>
[r: REST.get('https://www.syrinscape.com/online/frontend-api/moods/19/play/?auth_token=dontshareyourauthtokens')]
</syntaxhighlight>
 
See this [https://www.syrinscape.com/online/ Syrinscape Online] page for more info.


|also=
|also=
[[RESTful Functions Overview|RESTful Functions Overview]]
[[RESTful Functions Overview|RESTful Functions Overview]]
|changes=
* '''1.5''' - Added to main MapTool build.
}}
}}
[[Category:RESTful Function]]
[[Category:RESTful Function]]

Latest revision as of 20:32, 20 April 2023

REST.get() Function

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

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

Usage

REST.get(url)
REST.get(url, getFullResponse)
REST.get(url, headers, getFullResponse)

Parameters

  • url - String containing the URL to the resource or collection of resources.
  • getFullResponse - Boolean (0:1). Optional. Set true(1) to get full response.
  • headers - JSON object. Optional JSON headers.

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:

Response: https://reqres.in/api/users/2 
{"data": {
  "id": 2,
  "first_name": "Janet",
  "last_name": "Weaver",
  "avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/josephstein/128.jpg"
}}


Full Response: https://reqres.in/api/users/2 
{
  "status": 200,
  "headers":   {
    "access-control-allow-origin": ["*"],
    "cf-ray": ["4b9244475b1b5432-LAX"],
    "content-type": ["application/json; charset=utf-8"],
    "date": ["Sun, 17 Mar 2019 22:05:09 GMT"],
    "etag": ["W/\"89-bSBFK27ZbQL+K8fMuJn/jZrcUuk\""],
    "expect-ct": ["max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\""],
    "server": ["cloudflare"],
    "set-cookie": ["__cfduid=d5f84a1d88f4b568cd9547d6f76b1712b1552860309; expires=Mon, 16-Mar-20 22:05:09 GMT; path=/; domain=.reqres.in; HttpOnly"],
    "x-powered-by": ["Express"]
  },
  "body": {"data":   {
    "id": 2,
    "first_name": "Janet",
    "last_name": "Weaver",
    "avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/josephstein/128.jpg"
  }}
}

Simple Syrinscape Example

From the Syrinscape forums.

[r: REST.get('https://www.syrinscape.com/online/frontend-api/moods/19/play/?auth_token=dontshareyourauthtokens')]
See this Syrinscape Online page for more info.

See Also