Next.js Plugin
The @shiftapi/next plugin integrates ShiftAPI with Next.js, providing the same automatic type generation during development.
Installation
Section titled “Installation”npm install shiftapi @shiftapi/nextConfiguration
Section titled “Configuration”Wrap your Next.js config with withShiftAPI:
import { withShiftAPI } from "@shiftapi/next";
export default withShiftAPI({ // your Next.js config here});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 |
import { client } from "@shiftapi/client";
const { data } = await client.POST("/hello", { body: { name: "World" },});
console.log(data.message);// ^? (property) message: stringThe plugin handles starting your Go server, proxying requests, and regenerating types — just like the Vite plugin.
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");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.