Quick Start
Create a new project
Section titled “Create a new project”npm create shiftapi@latestThis scaffolds a full-stack Go + TypeScript app with end-to-end types.
Or add to an existing Go project
Section titled “Or add to an existing Go project”Install the Go package
Section titled “Install the Go package”go get github.com/fcjr/shiftapiDefine your API
Section titled “Define your API”package main
import ( "log" "net/http"
"github.com/fcjr/shiftapi")
type HelloRequest struct { Name string `json:"name" validate:"required"`}
type HelloResponse struct { Message string `json:"message"`}
func main() { api := shiftapi.New(shiftapi.WithInfo(shiftapi.Info{ Title: "My API", Version: "1.0.0", }))
shiftapi.Handle(api, "POST /hello", func(r *http.Request, in HelloRequest) (*HelloResponse, error) { return &HelloResponse{Message: "Hello, " + in.Name + "!"}, nil })
log.Fatal(shiftapi.ListenAndServe(":8080", api))}Add the frontend plugin
Section titled “Add the frontend plugin”npm install shiftapi @shiftapi/vite-pluginimport { defineConfig } from "vite";import { shiftapi } from "@shiftapi/vite-plugin";
export default defineConfig({ plugins: [shiftapi()],});npm install shiftapi @shiftapi/nextimport { withShiftAPI } from "@shiftapi/next";
export default withShiftAPI({});Use the typed client
Section titled “Use the typed client”import { client } from "shiftapi/client";
const { data } = await client.POST("/hello", { body: { name: "World" },});
console.log(data.message);// ^? (property) message: string