0.6.0 • Published 10 months ago

@4a/http v0.6.0

Weekly downloads
-
License
-
Repository
-
Last release
10 months ago

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

10 months ago

0.4.0

10 months ago

0.6.0

10 months ago

0.3.1

4 years ago

0.3.0

4 years ago

0.2.6

4 years ago

0.2.5

4 years ago

0.2.4

4 years ago

0.2.3

4 years ago

0.2.1

4 years ago

0.2.2

4 years ago

0.2.0

4 years ago