axiox
Axoix is an enhancement for axios which adds features like simpler error handling.
npm i @dasdarki/axiox axios
Usage
Import Axiox function from the library:
import Axiox from '@dasdarki/axiox';
Create axios instance (optional):
const axios = axios.create({});
Initialize Axiox Client:
const axioxClient = Axiox(axios);
Make a request:
axioxClient.get('https://api.some-url.com/some-path')
.then(response => {
// next step
})
.catch(error => {
console.log(error);
});
Handle the response with conditional response handling:
response.when()
.success(() => { /* SUCCESS (status code >= 200) */ })
.and(c => c.status(400).data('message', 'Username does not exist'), () => { /* BAD REQUEST */ })
.and(c => c.status(400).data('message', 'Email does not exist'), () => { /* BAD REQUEST */ })
Credits
- axios for creating the axios REST client