api-request-adapter v1.0.20
About The Project
An request library adapter to accomodate multiple request libraries
A list of commonly used resources that I find helpful are listed in the acknowledgements.
Prerequisites
This is an example of how to list things you need to use the software and how to install them.
- npm
npm install npm@latest -g
Installation
- Install NPM packages
npm i api-request-adapter
Usage
const { Request, FetchAdapter, AxiosAdapter } = require("./index");
const runAxios = async () => {
const request = new Request(new AxiosAdapter());
let response = await request.get("https://jsonplaceholder.typicode.com/todos/1");
console.log("Axios: ", response);
}
const runFetch = async () => {
const request = new Request(new FetchAdapter());
let response = await request.get("https://jsonplaceholder.typicode.com/todos/1");
console.log("Fetch: ", response);
}
const run = async () => {
await runAxios();
await runFetch();
}
run();
Documentation
Classes
FetchAdapter
Kind: global class
new FetchAdapter(token, fetchLibrary)
Instantiate the Fetch Adapter
Param | Type | Description |
---|---|---|
token | String | (Optional) Bearer Token |
fetchLibrary | Object | (Optional) pass in the fetch object if using on browser |
AxiosAdapter
Kind: global class
new AxiosAdapter(token)
Instantiate The Axios Adapter
Param | Type | Description |
---|---|---|
token | string | bearer token |
Request
Kind: global class
- Request
- new Request(adapter)
- .get(url, queryParameters) ⇒ Promise
- .delete(url, queryParameters, body) ⇒ Promise
- .post(url, queryParameters, body) ⇒ Promise
- .put(url, queryParameters, body) ⇒ Promise
- .patch(url, queryParameters, body) ⇒ Promise
new Request(adapter)
Instantiate the request library
Param | Type | Description |
---|---|---|
adapter | Object | FetchAdapter or AxiosAdapter object expected |
request.get(url, queryParameters) ⇒ Promise
GET HTTP request
Kind: instance method of Request
Returns: Promise - resolves into the JSON object of given request
Param | Type | Description |
---|---|---|
url | string | |
queryParameters | object | key, pair which includes query parameter |
request.delete(url, queryParameters, body) ⇒ Promise
DELETE HTTP request
Kind: instance method of Request
Returns: Promise - resolves into the JSON object of given request
Param | Type | Description |
---|---|---|
url | string | |
queryParameters | object | key, pair which includes query parameter |
body | object | key, pair which will be the request json bodyr |
request.post(url, queryParameters, body) ⇒ Promise
POST HTTP request
Kind: instance method of Request
Returns: Promise - resolves into the JSON object of given request
Param | Type | Description |
---|---|---|
url | string | |
queryParameters | object | key, pair which includes query parameter |
body | object | key, pair which will be the request json bodyr |
request.put(url, queryParameters, body) ⇒ Promise
PUT HTTP request
Kind: instance method of Request
Returns: Promise - resolves into the JSON object of given request
Param | Type | Description |
---|---|---|
url | string | |
queryParameters | object | key, pair which includes query parameter |
body | object | key, pair which will be the request json bodyr |
request.patch(url, queryParameters, body) ⇒ Promise
PATCH HTTP request
Kind: instance method of Request
Returns: Promise - resolves into the JSON object of given request
Param | Type | Description |
---|---|---|
url | string | |
queryParameters | object | key, pair which includes query parameter |
body | object | key, pair which will be the request json body |
License
Distributed under the MIT License. See LICENSE
for more information.
Contact
Ritwik Mukherjee - @idrit - mritwik369@gmail.com
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago