api-def
TypeScript icon, indicating that this package has built-in type declarations

0.10.1 • Public • Published

api-def · GitHub license npm version build status

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

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 } }

Package Sidebar

Install

npm i api-def

Weekly Downloads

208

Version

0.10.1

License

MIT

Unpacked Size

255 kB

Total Files

123

Last publish

Collaborators

  • censkh