npm.io
0.0.1 • Published 6 years ago

rexios

Licence
MIT
Version
0.0.1
Deps
0
Size
12 kB
Vulns
0
Weekly
0
Stars
5

rexios

Utils normalize url params and data for axios rest api request

Actions Statusnodenpm versionDependency StatusXO code styleCoveralls status

npm downloadsnpm

Why?

Returns normalized parameters and url according to the rest-api convention and saving a single request contract for axios

Install

$ npm install vue-rexios

Note: This project is compatible with node v10+

Usage

GET
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
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
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
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/']

axios[method](...args).then(response => {
  console.log(response);
});

Keywords