REST.post

From RPTools Wiki
Revision as of 03:58, 16 March 2019 by Phergus (talk | contribs) (Created page with "{{MacroFunction |name=REST.post |trusted=true |version=1.5 |description= Perform an HTTP post request to the specified URL to create a resource. |usage= <source lang="mtmacro...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

REST.post() Function

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

Introduced in version 1.5
Perform an HTTP post request to the specified URL to create a resource.

Usage

REST.post(url, payload, mediaType, getFullResponse)
REST.post(url, payload, mediaType, headers, getFullResponse)

Parameters

  • url -
  • payload -
  • mediaType -
  • headers -
  • 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

Create a user with a post request.
[h: baseurl = "https://reqres.in"]
[h: path = "/api/users"]
[h: mediaType = "application/json; charset=utf-8"]
[h: getFullResponse = 1]

[h: payload = '{ "name": "morpheus", "job": "leader" }']

[h: response = REST.post(baseurl + path, payload, mediaType, getFullResponse)]

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

Returns:

TEXT HERE

See Also

Version Changes

  • 1.5 - Added to main MapTool build.