1.0.20 • Published 3 years ago

api-request-adapter v1.0.20

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

MIT License

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

  1. 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

ParamTypeDescription
tokenString(Optional) Bearer Token
fetchLibraryObject(Optional) pass in the fetch object if using on browser

AxiosAdapter

Kind: global class

new AxiosAdapter(token)

Instantiate The Axios Adapter

ParamTypeDescription
tokenstringbearer token

Request

Kind: global class

new Request(adapter)

Instantiate the request library

ParamTypeDescription
adapterObjectFetchAdapter 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

ParamTypeDescription
urlstring
queryParametersobjectkey, 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

ParamTypeDescription
urlstring
queryParametersobjectkey, pair which includes query parameter
bodyobjectkey, 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

ParamTypeDescription
urlstring
queryParametersobjectkey, pair which includes query parameter
bodyobjectkey, 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

ParamTypeDescription
urlstring
queryParametersobjectkey, pair which includes query parameter
bodyobjectkey, 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

ParamTypeDescription
urlstring
queryParametersobjectkey, pair which includes query parameter
bodyobjectkey, 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

1.0.20

3 years ago

1.0.19

3 years ago

1.0.18

3 years ago

1.0.17

3 years ago

1.0.16

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago