REST.delete: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
(Created page with "{{MacroFunction |name=REST.delete |trusted=true |version=1.5 |description= Perform an HTTP delete request to the specified URL to delete the specified resource. |usage= <sour...")
 
m (Taustin moved page rEST.delete to REST.delete without leaving a redirect)
 
(9 intermediate revisions by 4 users not shown)
Line 2: Line 2:
|name=REST.delete
|name=REST.delete
|trusted=true
|trusted=true
|version=1.5
|version=1.5.0
|compatibility=1.5.7
|description=
|description=
Perform an HTTP delete request to the specified URL to delete the specified resource.
Perform an HTTP delete request to the specified URL to delete the specified resource.


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


'''Parameters'''
'''Parameters'''
{{param|url|}}
{{param|url|String containing the URL to the resource or collection of resources.}}
{{param|headers|}}
{{param|payload|JSON object containing the key:value pairs.}}
{{param|getFullResponse|Boolean (0:1) to get full response.}}
{{param|mediaType|String containing a MIME type and charset. See example, but note that any character encoding other than {{code|UTF-8}} will be extremely difficult to produce in MapTool.}}
{{param|headers|JSON object containing header key:value pairs.}}
{{param|getFullResponse|Boolean (0:1). True(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.
'''Note:''' The delete request returns an empty string for status 204 if the full response is not requested.


|example=
|example=
Delete the indicated resource.
Delete the indicated resource:
<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"]
 
[h: mediaType = "application/json; charset=utf-8"]
[r: response = REST.delete(baseURL + path, 1)]
[h: getFullResponse = 1]
<br><br>
[r: response = REST.delete(baseURL + path, 0)]
[h: payload = '{ "name": "smith", "job": "agent" }']
</source>
[h: response = REST.delete(baseurl + path, payload, mediaType, getFullResponse)]
<br>
<pre>
[r: json.indent(response, 2)]
</pre>
</syntaxhighlight>
Returns:
Returns:
<source lang="mtmacro" line>
Note the 204 - No Content status and thus no "body" element in the JSON. If the <code>getFullResponse</code> parameter had been 0, an empty string would have been returned.
TEXT HERE
<syntaxhighlight lang="mtmacro" line>
</source>
Full Response: {
  "status": 204,
  "headers":  {
    "access-control-allow-origin": ["*"],
    "cf-cache-status": ["DYNAMIC"],
    "cf-ray": ["533501e1ee362a47-SEA"],
    "date": ["Sun, 10 Nov 2019 03:40:51 GMT"],
    "etag": ["W/\"2-vyGp6PvFo4RvsFtPoIWeCReyIC8\""],
    "expect-ct": ["max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\""],
    "server": ["cloudflare"],
    "set-cookie": ["__cfduid=d6d2ff57f7c34e64294da00c51c3b9e3b1573357250; expires=Mon, 09-Nov-20 03:40:50 GMT; path=/; domain=.reqres.in; HttpOnly; Secure"],
    "via": ["1.1 vegur"],
    "x-powered-by": ["Express"]
  }
}
</syntaxhighlight>


|also=
|also=
Line 39: Line 65:


|changes=
|changes=
* '''1.5''' - Added to main MapTool build.
* '''1.5.7''' - Altered parameters to line up with other REST functions.
}}
}}
[[Category:RESTful Function]]
[[Category:RESTful Function]]

Latest revision as of 23:59, 10 May 2023

REST.delete() Function

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

Introduced in version 1.5.0
Last checked for compatibility with version 1.5.7
Perform an HTTP delete request to the specified URL to delete the specified resource.

Usage

REST.delete(url, payload, mediaType, getFullResponse)
REST.delete(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, but note that any character encoding other than UTF-8 will be extremely difficult to produce in MapTool.
  • headers - JSON object containing header key:value pairs.
  • getFullResponse - Boolean (0:1). 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.

Note: The delete request returns an empty string for status 204 if the full response is not requested.

Example

Delete the indicated resource:
[h: baseurl = "https://reqres.in"]
[h: path = "/api/users"]
[h: mediaType = "application/json; charset=utf-8"]
[h: getFullResponse = 1]
 
[h: payload = '{ "name": "smith", "job": "agent" }']
 
[h: response = REST.delete(baseurl + path, payload, mediaType, getFullResponse)]
 
<br>
<pre>
[r: json.indent(response, 2)]
</pre>

Returns: Note the 204 - No Content status and thus no "body" element in the JSON. If the getFullResponse parameter had been 0, an empty string would have been returned.

Full Response: {
  "status": 204,
  "headers":   {
    "access-control-allow-origin": ["*"],
    "cf-cache-status": ["DYNAMIC"],
    "cf-ray": ["533501e1ee362a47-SEA"],
    "date": ["Sun, 10 Nov 2019 03:40:51 GMT"],
    "etag": ["W/\"2-vyGp6PvFo4RvsFtPoIWeCReyIC8\""],
    "expect-ct": ["max-age=604800, report-uri=\"https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct\""],
    "server": ["cloudflare"],
    "set-cookie": ["__cfduid=d6d2ff57f7c34e64294da00c51c3b9e3b1573357250; expires=Mon, 09-Nov-20 03:40:50 GMT; path=/; domain=.reqres.in; HttpOnly; Secure"],
    "via": ["1.1 vegur"],
    "x-powered-by": ["Express"]
  }
}

See Also

Version Changes

  • 1.5.7 - Altered parameters to line up with other REST functions.