@aspida/ky
TypeScript icon, indicating that this package has built-in type declarations

0.10.2 • Public • Published

@aspida/ky





aspida




ky client for aspida.


Getting Started

Installation

  • Using npm:

    $ npm install @aspida/ky ky
  • Using Yarn:

    $ yarn add @aspida/ky ky

Make HTTP request from application

src/index.ts

import ky from "ky"
import aspida from "@aspida/ky"
import api from "../api/$api"

const kyConfig = { timeout: 3000, prefixUrl: "https://example.com/api" }
const client = api(aspida(ky, kyConfig))
;(async () => {
  const userId = 0
  const limit = 10

  await client.v1.users.post({ name: "mario" })

  const res = await client.v1.users.get({ query: { limit } })
  console.log(res)
  // req -> GET: https://example.com/api/v1/users/?limit=10
  // res -> { status: 200, data: [{ id: 0, name: "mario" }], headers: {...} }

  const user = await client.v1.users._userId(userId).$get()
  console.log(user)
  // req -> GET: https://example.com/api/v1/users/0
  // res -> { id: 0, name: "mario" }
})()

License

@aspida/ky is licensed under a MIT License.

Package Sidebar

Install

npm i @aspida/ky

Weekly Downloads

211

Version

0.10.2

License

MIT

Unpacked Size

11.9 kB

Total Files

7

Last publish

Collaborators

  • m-mitsuhide
  • solufa