@aspida/node-fetch
Getting Started
Installation
Make HTTP request from application
src/index.ts
import fetch, { Response } from "node-fetch"
import aspida, { HTTPError } from "@aspida/node-fetch"
import api from "../api/$api"
const fetchConfig = {
baseURL: "https://example.com/api",
throwHttpErrors: true
}
const client = api(aspida(fetch, fetchConfig))
;(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)
try {
const user = await client.v1.users._userId(userId).$get()
console.log(user)
} catch (e) {
if (e instanceof HTTPError) {
console.log(e.response instanceof Response)
} else {
console.log(e.message)
}
}
})()
License
@aspida/node-fetch is licensed under a MIT License.