@4a/http
TypeScript icon, indicating that this package has built-in type declarations

0.6.0 • Public • Published

HTTP

peerDependencies

  • axios@^1.2.0

Install

npm i @4a/http
pnpm add @4a/http

Usage

import { createHttp } from '@4a/http'
type AnyFunction<T> = (...args: any[]) => T
type API = Record<string, AnyFunction<AxiosRequestConfig>>

createHttp(api: API, opt?: AxiosRequestConfig)
// api.ts
// Example
export const api = {
  ok(params: Item): AxiosRequestConfig {
    return {
      params,
      method: 'GET',
      url: '/ok',
    }
  }
}
const http = createHttp(api)

const http = createHttp(api, { timeout: 5000 })

http.ok({ a: 1 })

More

export function createFactory(config: any) {
  return createHttp(api(config), {
    headers: {
      'Content-Type': 'application/json',
    },
    transformRequest(data: any) {
      return JSON.stringify(signed(data, config.secret))
    }
  })
}

/@4a/http/

    Package Sidebar

    Install

    npm i @4a/http

    Weekly Downloads

    2

    Version

    0.6.0

    License

    none

    Unpacked Size

    5.63 kB

    Total Files

    10

    Last publish

    Collaborators

    • gavinning