CLI (No Framework)
If you’re not using the Vite or Next.js plugin, you can generate the typed client directly with the shiftapi CLI.
Installation
Section titled “Installation”npm install -D shiftapiConfiguration
Section titled “Configuration”Create a shiftapi.config.ts in your project root:
import { defineConfig } from "shiftapi";
export default defineConfig({ server: "./cmd/server",});Config options
Section titled “Config options”| Option | Default | Description |
|---|---|---|
server | — | Path to your Go server entry point (required) |
url | "http://localhost:8080" | Address your Go server listens on |
baseUrl | "/" | Base URL for the generated client |
Generate the client
Section titled “Generate the client”npx shiftapi prepareThis will:
- Run your Go server to extract the OpenAPI 3.1 spec
- Generate TypeScript types via
openapi-typescript - Write
.shiftapi/client.d.tsand.shiftapi/client.js - Patch
tsconfig.jsonwith the required path mapping
To keep types up to date automatically, add it as a postinstall script:
{ "scripts": { "postinstall": "shiftapi prepare" }}import { client } from "@shiftapi/client";
const { data } = await client.POST("/hello", { body: { name: "World" },});
console.log(data.message);// ^? (property) message: stringTanStack Query
Section titled “TanStack Query”Wrap the generated client with openapi-react-query to get typed useQuery and useMutation hooks:
npm install @tanstack/react-query openapi-react-queryimport createClient from "openapi-react-query";import { client } from "@shiftapi/client";
export const api = createClient(client);const health = api.useQuery("get", "/health");const greet = api.useMutation("post", "/greet");ShiftAPI ships a built-in Svelte Query wrapper. Install the peer dependencies and use shiftapi/client/svelte to get typed createQuery and createMutation functions:
npm install @tanstack/svelte-queryimport createClient from "shiftapi/client/svelte";import { client } from "@shiftapi/client";
export const api = createClient(client);<script lang="ts"> const health = api.createQuery("get", "/health"); const greet = api.createMutation("post", "/greet");</script>