@ackee/antonio-core 中文文档教程

发布于 3年前 浏览 17 项目主页 更新于 3年前

ackee|Antonio

GitHub licenseCI StatusPRs WelcomeDependency Statusbundlephobiabundlephobianode version

@ackee/antonio-core

基于 Fetch API 构建的 HTTP 客户端。

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)

使用自定义请求配置和常规配置创建 Antonio 的新实例:

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

可选的 @ackee/antonio-core 配置:

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

ackee|Antonio

GitHub licenseCI StatusPRs WelcomeDependency Statusbundlephobiabundlephobianode 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,
}
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文