Table of Contents
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
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
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 |
Promise
request.get(url, queryParameters) ⇒ 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 |
Promise
request.delete(url, queryParameters, body) ⇒ 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 |
Promise
request.post(url, queryParameters, body) ⇒ 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 |
Promise
request.put(url, queryParameters, body) ⇒ 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 |
Promise
request.patch(url, queryParameters, body) ⇒ 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