1.0.0-rc.8 • Published 4 days ago

http-svc v1.0.0-rc.8

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
4 days ago

HTTP Service

What is

HTTP Service 是一个基于中间件组织模式,同时也是基于洋葱模式的 JavaScript Request SDK,它既可以帮助你快速发起一个简单的 HTTP 请求,也可以集成社区通用的中间件以构建复杂的请求过程。

Quick start

请前往文档站点,查看快速开始

此处仅提供简单的示例

  • Base
import { HttpService } from 'http-svc';

const httpSvc = new HttpService();

httpSvc
    .request({
        url: 'https://httpbin.org/get',
        method: 'GET',
        params: {
            a: 1,
            b: 2,
        },
        timeout: 1000,
        // ...其他配置
    })
    .then((res) => {
        console.log(res);
    });
  • With Middleware
import { HttpService } from 'http-svc';

const httpSvc = new HttpService();

httpSvc
    .with(async (ctx, next) => {
        console.log('before request');
        await next()
        console.log('after request');
    })
    .request({
        url: 'https://httpbin.org/get',
        method: 'GET',
        params: {
            a: 1,
            b: 2,
        },
        timeout: 1000,
        // ...其他配置
    }).then((res) => {
        console.log(res);
    });

Polyfill

npm install --save abortcontroller-polyfill
  • Browser
import 'abortcontroller-polyfill/dist/polyfill-patch-fetch'
  • Node

因为node环境我们要结合node-fetch发起请求,可以使用@http-svc/server-fetch,请参考该中间件的文档

其依赖的AbortController可以使用下列方式引入

import 'abortcontroller-polyfill/dist/abortcontroller-polyfill-only'
1.0.0-rc.8

4 days ago

1.0.0-rc.7

23 days ago

1.0.0-rc.6

2 months ago

1.0.0-rc.5

4 months ago

1.0.0-rc.4

4 months ago

1.0.0-rc.3

4 months ago

1.0.0-rc.2

4 months ago

1.0.0-rc.1

4 months ago