Package Exports
- fetchdts
Readme
fetchdts
A suite of type utilities for building strongly-typed APIs
π§ Under active development
Features
- πͺ Strongly-typed query, body, headers, response.
- πΊοΈ Static path segments, as well as dynamic and wildcard parameters.
- π¦ Exposes core utilities for building typed fetch functions.
Usage
Install package:
# npm
npm install fetchdts
# pnpm
pnpm install fetchdts
import type { DynamicParam, Endpoint, TypedFetchInput, TypedFetchResponse, WildcardParam } from 'fetchdts'
interface Schema {
'/api': {
'/test': {
[Endpoint]: {
POST: {
body: { foo: string }
response: { bar: string }
}
}
}
[DynamicParam]: {
[Endpoint]: {
GET: {
body: { id: boolean }
response: string
}
}
}
}
}
async function typedFetch<T extends TypedFetchInput<Schema>>(_input: T) {
return {} as Promise<TypedFetchResponse<Schema, T>>
}
const _res = await typedFetch('/api/foo')
// typed as string
π» Development
- Clone this repository
- Enable Corepack using
corepack enable
- Install dependencies using
pnpm install
- Run interactive tests using
pnpm dev
License
Made with β€οΈ
Published under MIT License.