web.delete
Sends an HTTP DELETE request to a URL.
js
web.delete(url, headers, base64Body)Parameters
| Parameter | Type | Description |
|---|---|---|
url | string | The URL to send the request to. |
headers | object | Optional. The request headers, keyed by header name. |
base64Body | boolean | Optional. true to always return the response body base64-encoded. Defaults to false. |
Returns
objectThe response:
status(number): the HTTP status code, or0when no response was received.headers(array): the response headers, each an object with one key/value pair.body(string): the response body.error(string): why the request failed, when no response was received.
Binary responses
Common binary types, such as images, PDFs and audio, are detected and returned base64-encoded. To save a file, use web.download.
Status and errors
A 4xx or 5xx status means the server received the request and returned an error. See HTTP status codes.
error is only set when the request fails before a response comes back. status is then usually 0. This can happen when:
- the URL is invalid or malformed.
- the connection or response times out.
- the network fails, such as a lost connection, a DNS problem, an SSL validation error or a blocked request.
- the server drops or rejects the request without responding.
Examples
js
const response = web.delete("https://api.example.com/users/12345", { "Authorization": "Bearer your_token" });
// Check if the response status code is in the success range (between 200 and 299, inclusive).
if (response.status >= 200 && response.status < 300) {
console.log("Request succeeded.");
console.log(response.body);
} else if (response.error) {
// An error occurred while sending the request (e.g., network error, timeout, etc.).
console.log("Error occurred while sending the request: " + response.error);
} else {
// The request failed with a non-success status code.
console.log("Request failed with status code: " + response.status);
console.log(response.body);
}