aync-http-request-package
v1.0.2
Published
Reusable http requests
Downloads
7
Maintainers
Readme
What is this?
This is a simple npm package that provides a reusable asynchronous HTTP request function for making HTTP requests using Axios. It supports GET, POST, PUT, and DELETE HTTP methods.
Installation
To install this package in your project, run the following command:
npm i aync-http-request-package
Usage
Importing the Package
import { get, post } from 'async-http-request-package;
Making HTTP Requests
Use the customeRequest function to make HTTP requests with flexibility:
const url = 'https://api.example.com/data';
const method = 'GET'; // Replace with 'POST', 'PUT', or 'DELETE' if needed
const data = { key: 'value' }; // Optional data for POST or PUT requests
(async () => {
try {
const response = await customeRequest(url, method, data);
console.log('Response:', response);
} catch (error) {
console.error('Error:', error);
}
})();
Customization
You can customize your requests by passing additional parameters to the customeRequest function, such as headers, query parameters, or authentication tokens:
headers: {
'Authorization': 'Bearer your_access_token',
'Custom-Header': 'custom-value',
},
params: {
page: 1,
limit: 10,
},
};
(async () => {
try {
const response = await sendRequest(url, method, data, options);
console.log('Response:', response);
} catch (error) {
console.error('Error:', error);
}
})();
Licence
This package is released under the MIT License.
In this `README.md`, you provide installation instructions, usage examples, customization options, and mention the license under which your package is distributed. Be sure to replace `'dynamic-http-requests'` with the actual name of your npm package. Additionally, customize the usage examples and descriptions according to the functionality of your package.