Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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: about 1 month 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 (about 4 years ago)
- Default Branch: master
- Last Pushed: 2021-11-11T07:05:27.000Z (about 3 years ago)
- Last Synced: 2024-10-05T14:13:48.529Z (about 2 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[![Actions Status](https://github.com/Scrum/rexios/workflows/Actions%20Status/badge.svg?style=flat-square)](https://github.com/Scrum/rexios/actions?query=workflow%3A%22CI+tests%22)[![node](https://img.shields.io/node/v/rexios.svg?style=flat-square)]()[![npm version](https://img.shields.io/npm/v/rexios.svg?style=flat-square)](https://www.npmjs.com/package/rexios)[![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg?style=flat-square)](https://github.com/xojs/xo)[![Coveralls status](https://img.shields.io/coveralls/Scrum/rexios.svg?style=flat-square)](https://coveralls.io/r/Scrum/rexios)
[![npm downloads](https://img.shields.io/npm/dm/rexios.svg?style=flat-square)](https://www.npmjs.com/package/rexios)[![npm](https://img.shields.io/npm/dt/rexios.svg?style=flat-square)](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);
});
```