New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@cogears/http-client

Package Overview
Dependencies
Maintainers
0
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cogears/http-client

http client module

  • 1.1.8
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

@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)
    }

    ...
}

Keywords

FAQs

Package last updated on 28 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc