axios-endpoint
v1.0.2
Published
Scalable and easy to use axios arch
Downloads
6
Readme
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