REST.put: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
m (Conversion script moved page REST.put to rEST.put: Converting page titles to lowercase)
m (Taustin moved page rEST.put to REST.put without leaving a redirect)
 
(One intermediate revision by the same user not shown)
Line 7: Line 7:


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


'''Parameters'''
'''Parameters'''
Line 24: Line 24:
|example=
|example=
Update a user with a put request.
Update a user with a put request.
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
[h: baseURL = "https://reqres.in"]
[h: baseURL = "https://reqres.in"]
[h: path = "/api/users/2"]
[h: path = "/api/users/2"]
Line 37: Line 37:
<pre>
<pre>
[r: json.indent(response, 2)]
[r: json.indent(response, 2)]
</pre></source>
</pre></syntaxhighlight>
Returns:
Returns:
<source lang="mtmacro" line>
<syntaxhighlight lang="mtmacro" line>
{
{
   "name": "morpheus",
   "name": "morpheus",
Line 45: Line 45:
   "updatedAt": "2019-03-17T22:49:52.188Z"
   "updatedAt": "2019-03-17T22:49:52.188Z"
}
}
</source>
</syntaxhighlight>


|also=
|also=

Latest revision as of 16:25, 10 May 2023

REST.put() Function

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

Introduced in version 1.5.0
Perform an HTTP put request to the specified URL to update an existing resource.

Usage

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

Parameters

  • url - String containing the URL to the resource or collection of resources.
  • payload - JSON object containing the key:value pairs.
  • mediaType - String containing a MIME type and charset. See example.
  • headers - JSON object containing header key:value pairs.
  • getFullResponse - Boolean (0:1). Use true(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

Update a user with a put request.
[h: baseURL = "https://reqres.in"]
[h: path = "/api/users/2"]
[h: mediaType = "application/json; charset=utf-8"]
[h: getFullResponse = 0]

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

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

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

Returns:

{
  "name": "morpheus",
  "job": "zion resident",
  "updatedAt": "2019-03-17T22:49:52.188Z"
}

See Also