Write APIs in TypeScript which compile to less than 400 bytes
npm install api-typifyWrite APIs in TypeScript which compile to less than 400 bytes.
With this package, developers can effortlessly define accurate and robust type definitions for their API responses, request payloads, and endpoints, reducing the risk of runtime errors and enhancing code maintainability.
``ts
// api.ts
const routes = {
GET: {
"/users/{id}": {
req: undefined, // Requests body type
res: User, // Response type
},
},
};
const api = getAPI
"https://api.example.com",
fetch,
);
// Get's the user object
const user = await api.get("/users/{id}", {
params: {
id: "123",
},
});
``