@ackee/antonio-core
HTTP client built on Fetch API.
Table of contents
Install
yarn add @ackee/antonio-core -S
Usage
import { Antonio } from '@ackee/antonio-core';
const api = new Antonio({
baseURL: 'https://jsonplaceholder.typicode.com/',
});
function* fetchTodos() {
const { data, request, response } = yield* api.get('/todos', {
params: {
page: 1,
limit: 20,
},
});
}
API
new Antonio(requestConfig?: RequestConfig, generalConfig?: GeneralConfig)
Creates a new instance of Antonio
with custom request config and general config:
import { Antonio } from '@ackee/antonio-core';
const api = new Antonio({
baseURL: 'https://some-domain.com/api/',
});
Instance methods
api.get(url: string, requestConfig?: RequestConfig): Generator<any, RequestResult>
api.delete(url: string, requestConfig?: RequestConfig): Generator<any, RequestResult>
api.head(url: string, requestConfig?: RequestConfig): Generator<any, RequestResult>
api.options(url: string, requestConfig?: RequestConfig): Generator<any, RequestResult>
api.post(url: string, data: RequestBody, requestConfig?: RequestConfig): Generator<any, RequestResult>
api.put(url: string, data: RequestBody, requestConfig?: RequestConfig): Generator<any, RequestResult>
api.patch(url: string, data: RequestBody, requestConfig?: RequestConfig): Generator<any, RequestResult>
generalConfig: GeneralConfig
Optional @ackee/antonio-core
configuration:
{
logger: loglevel,
}