0.1.7 • Published 6 months ago

@inkheart/queryframe v0.1.7

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

NPM Contributors Forks Stargazers Issues MIT License

Documentation

This library implements a highly opinionated way of fetching and managing API data.

Queryframe is a typesafe API SDK generator for REST endpoints and exposes hooks from the amazing @tanstack/react-query.

Tech

Queryframe uses a number of open source projects under the hood:

Installation

Install the dependencies and follow the guide below.

pnpm add @inkheart/queryframe

Example Usage

import { createQueryframeBuilder, z } from '@inkheart/queryframe'

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
export const queryClient = builder.queryClient
export { QueryClientProvider } from '@inkheart/queryframe'

useQuery interface

import queryframe from '...'

const { data } = await queryframe.getExpenseCategories.useQuery(
  {},
  {
    refetchInterval: data => 1000,
  },
)

Handle interface

import queryframe from '...'

try {
  const result = await queryframe.getExpenseCategories.handle({})
} catch (error) {
  console.error(error)
}
0.1.7

6 months ago

0.1.6

7 months ago

0.1.5

7 months ago

0.1.4

7 months ago

0.1.3

7 months ago

0.1.2

7 months ago

0.1.1

7 months ago

0.1.0

7 months ago

0.0.9

7 months ago

0.0.8

7 months ago

0.0.7

7 months ago

0.0.6

7 months ago

0.0.5

7 months ago

0.0.4

7 months ago

0.0.3

7 months ago

0.0.2

7 months ago

0.0.1

7 months ago