JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 825
  • Score
    100M100P100Q94209F
  • License MIT

A suite of type utilities for building strongly-typed APIs

Package Exports

  • fetchdts

Readme

fetchdts

npm version npm downloads Github Actions Codecov

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.