1.1.7 • Published 1 year ago

@cogears/http-client v1.1.7

Weekly downloads
-
License
-
Repository
github
Last release
1 year ago

@cogears/http-client

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

安装

npm install @cogears/http-client

接口列表

  • HttpClient
  • HttpApi

具体实现可以查看types定义

用例

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

const http = new 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.7

1 year ago

1.1.6

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago