2.0.4 • Published 4 months ago

@cogears/http-client v2.0.4

Weekly downloads
-
License
-
Repository
github
Last release
4 months ago

@cogears/http-client

http客户端模块,同时兼容浏览器和node环境。

安装

npm install @cogears/http-client

接口列表

  • HttpClient
  • HttpApi

具体实现可以查看types定义

用例

  • 直接使用HttpClient发起请求,适用于少量http请求的场景:
import HttpClient from '@cogears/http-client'

const http = HttpClient()
let {status, body, headers} = await http.get(url)

await http.post(url, http.json({name:'tom'}))
  • 使用HttpApi包装器,适用于有大量业务接口需要统一管理的场景:
import {HttpApi} from '@cogears/http-client'

class MyApi extends HttpApi {
    constructor() {
        super(domain)
    }

    preRequest({query, body, headers}) {
        return {query, body, headers}
    }

    async postRequest(response, url) {
        response = await super.postRequest(response, url)
        return response
    }

    doSomeRequest(){
        return this.get(apiUrl)
    }

    ...
}
1.1.8

9 months ago

2.0.3

4 months ago

2.0.2

4 months ago

2.0.4

4 months ago

2.0.1

4 months ago

2.0.0

4 months ago

1.1.7

1 year ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago