api-request-adapter

1.0.20 • Public • Published

MIT License

Table of Contents
  1. About The Project
  2. Prerequisites
  3. Installation
  4. Usage
  5. Documentation
  6. License
  7. Contact

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
AxiosAdapter
Request

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

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

Package Sidebar

Install

npm i api-request-adapter

Weekly Downloads

2

Version

1.0.20

License

MIT

Unpacked Size

19.2 kB

Total Files

4

Last publish

Collaborators

  • idrit