https://github.com/scrum/rexios
Utils normalize url, data, params for axios when using rest api request
https://github.com/scrum/rexios
axios normalize rest-api vue
Last synced: 3 months ago
JSON representation
Utils normalize url, data, params for axios when using rest api request
- Host: GitHub
- URL: https://github.com/scrum/rexios
- Owner: Scrum
- License: mit
- Created: 2020-09-15T15:05:04.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-11-11T07:05:27.000Z (over 3 years ago)
- Last Synced: 2025-02-21T09:57:36.799Z (4 months ago)
- Topics: axios, normalize, rest-api, vue
- Language: JavaScript
- Homepage:
- Size: 118 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- Changelog: changelog.md
- Funding: .github/funding.yml
- License: license
Awesome Lists containing this project
README
# rexios
> Utils normalize url, data, params for [axios](https://github.com/axios/axios) when using rest api request[](https://github.com/Scrum/rexios/actions?query=workflow%3A%22CI+tests%22)[]()[](https://www.npmjs.com/package/rexios)[](https://github.com/xojs/xo)[](https://coveralls.io/r/Scrum/rexios)
[](https://www.npmjs.com/package/rexios)[](https://www.npmjs.com/package/rexios)
## Why?
Returns normalized parameters and url according to the rest-api convention and saving a single request contract for [axios](https://github.com/axios/axios)## Install
```bash
$ npm install rexios
```> **Note:** This project is compatible with node v10+
## Usage
### `GET`
```js
const axios = require('axios');
const rexios = require('rexios');const method = 'get';
const baseURL = 'v2/api/user/';
const params = {
id: 123,
article: 1,
};const { args } = rexios({
method,
baseURL,
params
});// args => ['v2/api/user/123/?article=1']
axios[method](...args).then(response => {
console.log(response);
});
```### `POST`
```js
const axios = require('axios');
const rexios = require('rexios');const method = 'post';
const baseURL = 'v2/api/user/';
const params = {
id: 123,
article: 1,
};const { args } = rexios({
method,
baseURL,
params
});// args => ['v2/api/user/', {id: 123, article: 1}]
axios[method](...args).then(response => {
console.log(response);
});
```### `PUT`
```js
const axios = require('axios');
const rexios = require('rexios');const method = 'put';
const baseURL = 'v2/api/user/';
const params = {
id: 123,
article: 1,
};const { args } = rexios({
method,
baseURL,
params
});// args => ['v2/api/user/123/', {id: 123, article: 1}]
axios[method](...args).then(response => {
console.log(response);
});
```### `DELETE`
```js
const axios = require('axios');
const rexios = require('rexios');const method = 'delete';
const baseURL = 'v2/api/user/';
const params = {
id: 123,
article: 1,
};const { args } = rexios({
method,
baseURL,
params
});// args => ['v2/api/user/123/']
axios[method](...args).then(response => {
console.log(response);
});
```