Skip to content

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.

Terminal window
npm install -D shiftapi

Create a shiftapi.config.ts in your project root:

shiftapi.config.ts
import { defineConfig } from "shiftapi";
export default defineConfig({
server: "./cmd/server",
});
OptionDefaultDescription
serverPath to your Go server entry point (required)
url"http://localhost:8080"Address your Go server listens on
baseUrl"/"Base URL for the generated client
Terminal window
npx shiftapi prepare

This will:

  1. Run your Go server to extract the OpenAPI 3.1 spec
  2. Generate TypeScript types via openapi-typescript
  3. Write .shiftapi/client.d.ts and .shiftapi/client.js
  4. Patch tsconfig.json with 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: string

Wrap the generated client with openapi-react-query to get typed useQuery and useMutation hooks:

Terminal window
npm install @tanstack/react-query openapi-react-query
import 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");