1.1.1 • Published 1 year ago

main-client v1.1.1

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

Main Client

This customizing Axios code will help you forget messy and not understandable code. It's clean and easy-working code and it will make the world a better place:)

Props

  • headers => headers is a prop for writing headers in the request, for example when you want to add Authorization in your request header,
  • statusHandler => It`s object with functions for error response statuses, for example in 404 error you should have a object
{
  on404: () => {
    // do something when 404 error occurs.
  };
}

as you already understand it's understood from the object name the error status and the function will work only in that status always, it's should starts with on and the default error responding key is "defaultErrHandler".

  • accessToken => accessToken is a string for getting the Authorization token,
  • type => the type is an array to get the user API, for example, if the type is 'update', it will return only the Promise function to update the backend. by default it will return all methods. And options are (getMany, getOne, update, add, delete).

Usage

this is a basic example how you can configure your main-client

import APIProvider from "main-client";

const accessToken = 'qwe123';

const statusHandler={
  on404:()=>{
    //  do something when 404 error occurs.
  }
  defaultErrHandler:()=>{
    //  do something when error occurs.
  }
}

const type = ['getMany','update'];

const headers = {
  isAdmin: 'true'
};

const provider = APIProvider({ headers, accessToken, statusHandler });

const [fetchAllUnitsApi, updateUnitApi] = provider('units', type);
1.1.1

1 year ago

1.1.0

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago