Vite Plugin
The @shiftapi/vite-plugin starts your Go server, proxies API requests, and regenerates TypeScript types on every save.
Installation
Section titled “Installation”npm install shiftapi @shiftapi/vite-pluginConfiguration
Section titled “Configuration”Add the plugin to your Vite config:
import { defineConfig } from "vite";import { shiftapi } from "@shiftapi/vite-plugin";
export default defineConfig({ plugins: [shiftapi()],});Then create a shiftapi.config.ts in your project root:
import { defineConfig } from "shiftapi";
export default defineConfig({ server: "./server/main.go",});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 |
What the plugin does
Section titled “What the plugin does”- Starts your Go server during development
- Proxies API requests to the Go server
- Fetches the OpenAPI spec from
/openapi.json - Generates a fully-typed TypeScript client in
.shiftapi/
import { client } from "@shiftapi/client";
const { data } = await client.POST("/hello", { body: { name: "World" },});
console.log(data.message);// ^? (property) message: stringTypes are regenerated automatically when you save a Go file — changes appear in your editor via Vite’s HMR.
TanStack 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>Server-Sent Events
Section titled “Server-Sent Events”The generated client includes an sse function for SSE endpoints registered with HandleSSE. It returns a typed async iterable:
import { sse } from "@shiftapi/client";
const stream = sse("/events");
for await (const event of stream) { console.log(event); // fully typed from your Go Event struct}See Server-Sent Events for full details.
WebSockets
Section titled “WebSockets”The generated client also includes a websocket function for WebSocket endpoints registered with HandleWS. It returns a typed bidirectional connection:
import { websocket } from "@shiftapi/client";
const ws = websocket("/chat");
ws.send({ text: "hello" });
for await (const msg of ws) { console.log(msg.text); // fully typed from your Go Send struct}See WebSockets for full details.