A module for making HTTP requests in Gingee applications.
This module provides functions to perform GET and POST requests, supporting various content types.
It abstracts the complexities of making HTTP requests, providing a simple interface for developers to interact with web services.
It supports both text and binary responses, automatically determining the response type based on the content-type header.
It is particularly useful for applications that need to fetch resources from external APIs or web services, and for sending data to web services in different formats.
It allows for flexible data submission, making it suitable for APIs that require different content types.
It provides constants for common POST data types, ensuring that the correct headers are set for the request.
IMPORTANT: Requires explicit permission to use the module. See docs/permissions-guide for more details.
- Description:
- A module for making HTTP requests in Gingee applications. This module provides functions to perform GET and POST requests, supporting various content types. It abstracts the complexities of making HTTP requests, providing a simple interface for developers to interact with web services. It supports both text and binary responses, automatically determining the response type based on the content-type header. It is particularly useful for applications that need to fetch resources from external APIs or web services, and for sending data to web services in different formats. It allows for flexible data submission, making it suitable for APIs that require different content types. It provides constants for common POST data types, ensuring that the correct headers are set for the request. IMPORTANT: Requires explicit permission to use the module. See docs/permissions-guide for more details.
Members
(static, constant) FORM
- Description:
- Constant for form-urlencoded content type in POST requests. This constant can be used to specify that the POST request body is in form-urlencoded format.
Constant for form-urlencoded content type in POST requests.
This constant can be used to specify that the POST request body is in form-urlencoded format.
(static, constant) JSON
- Description:
- Constant for JSON content type in POST requests. This constant can be used to specify that the POST request body is in JSON format.
Constant for JSON content type in POST requests.
This constant can be used to specify that the POST request body is in JSON format.
(static, constant) MULTIPART
- Description:
- Constant for multipart/form-data content type in POST requests. This constant can be used to specify that the POST request body is in multipart/form-data format.
Constant for multipart/form-data content type in POST requests.
This constant can be used to specify that the POST request body is in multipart/form-data format.
(static, constant) TEXT
- Description:
- Constant for plain text content type in POST requests. This constant can be used to specify that the POST request body is in plain text format.
Constant for plain text content type in POST requests.
This constant can be used to specify that the POST request body is in plain text format.
(static, constant) XML
- Description:
- Constant for XML content type in POST requests. This constant can be used to specify that the POST request body is in XML format.
Constant for XML content type in POST requests.
This constant can be used to specify that the POST request body is in XML format.
Methods
(static) get(url, optionsopt) → {Promise.<{status: number, headers: object, body: (string|Buffer)}>}
- Description:
- Performs an HTTP GET request. This function retrieves data from a specified URL and returns the response status, headers, and body. It supports both text and binary responses, automatically determining the response type based on the content-type header. It abstracts the complexities of making HTTP requests, providing a simple interface for developers to fetch data from the web. It can handle various content types, including JSON, text, and binary data, making it versatile for different use cases. It is particularly useful for applications that need to fetch resources from external APIs or web services.
Example
const response = await httpclient.get('https://api.example.com/data');
console.log(response.body);
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
url |
string | The URL to request. | |
options |
object |
<optional> |
Axios request configuration options (e.g., headers). |
Throws:
-
If the request fails or if the response body cannot be processed.
- Type
- Error
Returns:
- Type
- Promise.<{status: number, headers: object, body: (string|Buffer)}>
(static) post(url, body, optionsopt) → {Promise.<{status: number, headers: object, body: (string|Buffer)}>}
- Description:
- Performs an HTTP POST request. This function sends data to a specified URL and returns the response status, headers, and body. It supports various content types, including JSON, form-urlencoded, plain text, XML, and multipart/form-data. It abstracts the complexities of making HTTP POST requests, providing a simple interface for developers to send data to web services. It allows for flexible data submission, making it suitable for APIs that require different content types.
Example
const response = await httpclient.post('https://api.example.com/data', { key: 'value' });
console.log(response.body);
Parameters:
Name | Type | Attributes | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
url |
string | The URL to post to. | |||||||||||
body |
any | The data to send in the request body. | |||||||||||
options |
object |
<optional> |
Axios request configuration options.
Properties
|
Throws:
-
If the request fails or if the body cannot be processed.
- Type
- Error
Returns:
- Type
- Promise.<{status: number, headers: object, body: (string|Buffer)}>