REST.delete: Difference between revisions

From RPTools Wiki
Jump to navigation Jump to search
(Partially updated for new function signature. Still needs updated example.)
m (Stopped referencing the example in the Parameters for now, since the example is old.)
Line 16: Line 16:
{{param|url|String containing the URL to the resource or collection of resources.}}
{{param|url|String containing the URL to the resource or collection of resources.}}
{{param|payload|JSON object containing the key:value pairs.}}
{{param|payload|JSON object containing the key:value pairs.}}
{{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|mediaType|String containing a MIME type and charset. 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|headers|JSON object containing header key:value pairs.}}
{{param|getFullResponse|Boolean (0:1). True(1) to get full response.}}
{{param|getFullResponse|Boolean (0:1). True(1) to get full response.}}

Revision as of 03:15, 10 November 2019

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. 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 (Pre-1.5.7):
[h: baseURL = "https://reqres.in"]
[h: path = "/api/users/2"]

[r: response = REST.delete(baseURL + path, 1)]

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

Full Response: {
  "status": 204,
  "headers":   {
    "access-control-allow-origin": ["*"],
    "cf-ray": ["4b928693e9805414-LAX"],
    "date": ["Sun, 17 Mar 2019 22:50:25 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=dc5a1bd174f8f46cb9721f3a3338cff631552863025; expires=Mon, 16-Mar-20 22:50:25 GMT; path=/; domain=.reqres.in; HttpOnly"],
    "x-powered-by": ["Express"]
  }
}

See Also

Version Changes

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