api-def ·
![build status](https://camo.githubusercontent.com/5b8f9bedd36ad430a53bb975aece6951de285097f2fbfe4d2b8689b970d55760/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f63656e736b682f6170692d6465662f776f726b666c6f772e796d6c)
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 } }