Constructor
new HTTPClient()
Example
// Post data to server
try {
var params = {
"headers": {"key1": "value1"}, // HTTP Headers
"body": {"a": "a1", "b":"b1"}, // HTTP Body (supports String, JSON, URLSearchParams)
};
const response = await HTTPClient.post("https://dummyjson.com/products/1", params);
console.log(response.body.parseText());
} catch(error) {
console.log(error);
}
Methods
(async, static) delete(url, params) → {Response}
Sends a DELETE request to the specified URL with optional request body.
Parameters:
Name | Type | Description |
---|---|---|
url | string | The URL to send the DELETE request to. |
params | object | Optional. The request body to include in the request. |
Returns:
- The response object.
- Type:
- Response
(async, static) get(url, params) → {Response}
Sends a GET request to the specified URL with optional query parameters.
Parameters:
Name | Type | Description |
---|---|---|
url | string | The URL to send the GET request to. |
params | object | Optional. Query parameters to include in the request. |
Returns:
- The response object.
- Type:
- Response
(async, static) post(url, params) → {Response}
Sends a POST request to the specified URL with optional request body.
Parameters:
Name | Type | Description |
---|---|---|
url | string | The URL to send the POST request to. |
params | object | Optional. The request body to include in the request. |
Returns:
- The response object.
- Type:
- Response
(async, static) put(url, params) → {Response}
Sends a PUT request to the specified URL with optional request body.
Parameters:
Name | Type | Description |
---|---|---|
url | string | The URL to send the PUT request to. |
params | object | Optional. The request body to include in the request. |
Returns:
- The response object.
- Type:
- Response
(async, static) request(url, method, params) → {Response}
Sends a custom request to the specified URL using the specified method and request configuration.
Parameters:
Name | Type | Description |
---|---|---|
url | string | The URL to send the request to. |
method | string | GET,POST,PUT,UPDATE,DELETE ... |
params | object | Optional. The request configuration, including headers and body. |
Returns:
- The response object.
- Type:
- Response
(async, static) update(url, params) → {Response}
Sends an UPDATE request to the specified URL with optional request body.
Parameters:
Name | Type | Description |
---|---|---|
url | string | The URL to send the UPDATE request to. |
params | object | Optional. The request body to include in the request. |
Returns:
- The response object.
- Type:
- Response