@ackee/antonio-core

A HTTP client built on fetch API with axios-like API.

Usage no npm install needed!

<script type="module">
  import ackeeAntonioCore from 'https://cdn.skypack.dev/@ackee/antonio-core';
</script>

README

ackee|Antonio

GitHub license"> CI Status PRs Welcome Dependency Status bundlephobia bundlephobia node version

@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() {
    // Since api.get returns generator function, `yield*` is required.
    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:

{
    // Default is [`loglevel`](https://www.npmjs.com/package/loglevel)
    logger: loglevel,
}