Antonio
A HTTP client built on Fetch API with similar API to axios.
Table of contents
Installing
$ yarn add @ackee/antonio -S
Setup
Create a new instance and you're ready to go.
import { create } from '@ackee/antonio';
export const api = create({
baseURL: 'https://jsonplaceholder.typicode.com/',
});
Usage Examples
import { api } from '...';
api.get('/todos').then(({ data, request, response }) => {
});
api.post('/todos', {
title: 'Lorem ipsum',
});
api.put(
'/todos/:id',
{
title: 'Not lorem ipsum',
},
{
uriParams: {
id: '2',
},
},
);
api.get('/todos/:id', {
uriParams: {
id: '2',
},
});
api.delete('/todos/:id', {
uriParams: '2',
});
API
create([config])
import * as Antonio from '@ackee/antonio';
const antonio = Antonio.create({
baseURL: 'https://some-domain.com/api/',
});
Instance methods
antonio#get(url[, config])
antonio#delete(url[, config])
antonio#head(url[, config])
antonio#options(url[, config])
antonio#post(url[, data[, config]])
antonio#put(url[, data[, config]])
antonio#patch(url[, data[, config]])
Request config
These are the available config options for making requests. None of these is required.
{
baseUrl: 'https://jsonplaceholder.typicode.com/',
responseType: "json",
uriParams: {
id: '2'
},
headers: new Headers({
'X-Custom-Header': 1234
}),
searchParams: new URLSearchParams({
query: 'foo'
}),
mode: undefined,
credentials: undefined,
cache: undefined,
redirect: undefined,
referrer: undefined,
referrerPolicy: undefined,
integrity: undefined,
keepalive: undefined,
signal: undefined,
}