web.put
Sends a HTTP PUT request to the specified URL.
js
web.put(url, headers, body, base64Body)
web.put(url, headers, body, base64Body)
Parameters
url
(string): The URL to send the PUT request to.headers
(object): An object containing custom headers to include in the request. The keys represent header names, and the values represent the corresponding header values.(optional)
body
(object|string): The request body data. It can be an object representing key-value pairs (to be serialized as JSON) or a string with the raw body data.(optional)
base64Body
(boolean): A boolean flag indicating whether the response body should be returned as a base64-encoded string. Default value isfalse
.(optional)
Returns
response
(object): An object representing the HTTP response containing the following properties:status
(number): The HTTP status code of the response.headers
(array): An array of header objects, where each object has one key/value pair representing a header.body
(string): The response body as a string or as a base64-encoded string if the content type is binary.error
(string): An error message if an exception occurred while sending the request.
Examples
js
var requestBody = { "name": "Updated Name" };
var response = web.put("https://api.example.com/users/12345", { "Content-Type": "application/json" }, requestBody);
// 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);
}
var requestBody = { "name": "Updated Name" };
var response = web.put("https://api.example.com/users/12345", { "Content-Type": "application/json" }, requestBody);
// 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);
}