A suite of type utilities for building strongly-typed APIs
🚧 Under active development
- 💪 Strongly-typed query, body, headers, response.
- 🗺️ Static path segments, as well as dynamic and wildcard parameters.
- 📦 Exposes core utilities for building typed fetch functions.
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
- Clone this repository
- Enable Corepack using
corepack enable
- Install dependencies using
pnpm install
- Run interactive tests using
pnpm dev
Made with ❤️
Published under MIT License.