Table of Contents
An request library adapter to accomodate multiple request libraries
A list of commonly used resources that I find helpful are listed in the acknowledgements.
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
- Install NPM packages
npm i api-request-adapter
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();Instantiate the Fetch Adapter
| Param | Type | Description |
|---|---|---|
| token | String |
(Optional) Bearer Token |
| fetchLibrary | Object |
(Optional) pass in the fetch object if using on browser |
Instantiate The Axios Adapter
| Param | Type | Description |
|---|---|---|
| token | string |
bearer token |
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
Instantiate the request library
| Param | Type | Description |
|---|---|---|
| adapter | Object |
FetchAdapter or AxiosAdapter object expected |
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 |
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 |
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 |
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 |
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 |
Distributed under the MIT License. See LICENSE for more information.
Ritwik Mukherjee - @idrit - mritwik369@gmail.com