FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Censkh/api-def: Typed APIs with middleware support · GitHub

/ api-def Public

Repository files navigation

Typed APIs with middleware support

API def provides a unified way to type your endpoints allowing for compile time checking of query, body, response and even url parameters

npm i api-def

Requires Node.js 22 or newer. Browser builds target ES2020 and support both ESM and CommonJS consumers.

import { Api } from "api-def";

const api = new Api({
  baseUrl: "https://my-api/",
  name: "My API",
});

const fetchData = api
  .endpoint()
  .queryOf<{ includeAwesome: boolean }>()
  .responseOf<{ data: { awesome: boolean } }>()
  .build({
    id: "fetch_data",
    method: "get",
    path: "/data",
  });

// calls GET https://my-api/data?includeAwesome=true
const res = await fetchData.submit({
  query: { includeAwesome: true },
});

console.log(res.data); // { data: { awesome: true } }

About

Typed APIs with middleware support

Topics

Resources

Stars

1 star

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages


Back | FazBrowse Home | New Git URL