Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/awesome-modules/axios-wrapper-helper
An NPM module which provides a reusable wrapper for axios.
https://github.com/awesome-modules/axios-wrapper-helper
List: axios-wrapper-helper
api axios helper npm-module npm-package resuable typescript wrapper
Last synced: 2 months ago
JSON representation
An NPM module which provides a reusable wrapper for axios.
- Host: GitHub
- URL: https://github.com/awesome-modules/axios-wrapper-helper
- Owner: awesome-modules
- Created: 2021-07-24T12:59:06.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-07-24T13:42:32.000Z (over 3 years ago)
- Last Synced: 2024-04-26T21:04:09.055Z (9 months ago)
- Topics: api, axios, helper, npm-module, npm-package, resuable, typescript, wrapper
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/axios-wrapper-helper
- Size: 5.86 KB
- Stars: 4
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# axios-wrapper-helper
## Installation
```sh
npm install axios-wrapper-helper
```or
```sh
yarn add axios-wrapper-helper
```## Usage
- First step is to setup general config:
```js
import { set_general_config } from "axios-wrapper-helper";const BASE_URL = "base_url";
const TOKEN_HEADER_KEY = "token_key_for_header"; // eg. 'Authorization'export const setUp = () => {
set_general_config(BASE_URL, TOKEN_HEADER_URL);
};
```- Next set is to use the provided resuable function:
```js
import { async_func_data } from "axios-wrapper-helper";try {
const response = await async_func_data(ROUTE, PARAMS_OR_DATA, METHOD, IS_TOKEN_REQUIRED, TOKEN);
// Handle response
} catch (err) {// Handle error
}
```| Param | Description | Example |
| ----------------- | ----------------------------------------------------------------- | ------------------------------ |
| ROUTE | API endpoint | /auth/login |
| PARAMS_OR_DATA | Request body in case of post request and params in case of others | {name: "XYZ", email:"emailid"} |
| METHOD | REQUEST_TYPE | "get","post","put","delete" |
| IS_TOKEN_REQUIRED | For authenticated routes, by default set to false. | true or false (boolean) |
| TOKEN | Required token | "asdfghj" (string) |ResponseType is the custom response type to be provided for making it typesafe, by default it's any.