axios-endpoint

1.0.2 • Public • Published

Axios endpoint

Manage and create axios requests without a hassle

Installation

npm i axios-endpoint

Usage

Import it

let route = require("axios-endpoint");
// es6
import route from "axios-endpoint";

(Optional) Configure axios as you like

const axios = require("axios");
axios.defaults.baseURL = "https://jsonplaceholder.typicode.com";

Use it

let endpoint = {
  getTodos: route("GET", "/todos/1").bundle(),
 
  getTodosBefore: route("GET", "/todos/1")
    .before(() => {
      console.log("this is gonna run before the request!");
    })
    .bundle(),
 
  getTodosAfter: route("GET", "/todos/1")
    .after(() => {
      console.log("this is gonna run after the request!");
    })
    .bundle(),
 
  getTodosBeforeAfter: route("GET", "/todos/1")
    .before(() => {
      console.log("this is gonna run before the request!");
    })
    .after(() => {
      console.log("this is gonna run after the request!");
    })
    .bundle()
};
 
endpoint
  .getTodos()
  .then(response => {
    console.log(response);
  })
  .catch(error => {
    console.error(error);
  });
endpoint
  .getTodosBefore()
  .then(response => {
    console.log(response);
  })
  .catch(error => {
    console.error(error);
  });
endpoint
  .getTodosAfter()
  .then(response => {
    console.log(response);
  })
  .catch(error => {
    console.error(error);
  });
endpoint
  .getTodosBeforeAfter()
  .then(response => {
    console.log(response);
  })
  .catch(error => {
    console.error(error);
  });

Callback hooks

before runs exactly before making the request

after runs exactly after making the request

Run tests

npm run test

Readme

Keywords

Package Sidebar

Install

npm i axios-endpoint

Weekly Downloads

1

Version

1.0.2

License

MIT

Unpacked Size

5.51 kB

Total Files

4

Last publish

Collaborators

  • nikandlv