Skip to content

Quick Start

Terminal window
npm create shiftapi@latest

This scaffolds a full-stack Go + TypeScript app with end-to-end types.

Terminal window
go get github.com/fcjr/shiftapi
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))
}
Terminal window
npm install shiftapi @shiftapi/vite-plugin
vite.config.ts
import { defineConfig } from "vite";
import { shiftapi } from "@shiftapi/vite-plugin";
export default defineConfig({
plugins: [shiftapi()],
});
import { client } from "shiftapi/client";
const { data } = await client.POST("/hello", {
body: { name: "World" },
});
console.log(data.message);
// ^? (property) message: string