Documentation
This library implements a highly opinionated way of fetching and managing API data.
Queryframe lite is a typesafe API SDK generator for REST endpoints.
Tech
Queryframe uses a number of open source projects under the hood:
- [Zod] - for schemas
- [Zocker] - 2kb library to generate mock data
- [Redaxios] - minimal fetch wrapper with axios interface
Installation
Install the dependencies and follow the guide below.
pnpm add @inkheart/queryframe-lite
Example Usage
import { createQueryframeBuilder, z } from "@inkheart/queryframe-lite";
const builder = createQueryframeBuilder({
baseURL: "https://api.sampleapis.com",
});
const getAvatars = builder.createQuery({
endpoint: "/avatar/info",
output: z
.object({
synopsis: z.string(),
})
.array(),
});
const { queryframe } = builder.createQueryframe({
getAvatars,
});
export default queryframe;
Handle interface
import queryframe from "...";
try {
const result = await queryframe.getExpenseCategories.handle({});
} catch (error) {
console.error(error);
}