0.2.0 • Published 4 months ago

@inkheart/queryframe-lite v0.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

NPM Contributors Forks Stargazers Issues MIT License

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

4 months ago

0.1.9

5 months ago

0.1.8

5 months ago

0.1.7

5 months ago