Skip to content

rivet-tsTypeScript contracts to working APIs

Write a contract, scaffold a workspace, point the UI at the typed client, and regenerate artifacts with one command.

Overview ​

  1. write a TypeScript contract (or let scaffold give you a worked example)
  2. scaffold the workspace once
  3. run task install && task dev
  4. consume the typed client from apps/ui/app/app.vue
  5. run task generate after contract changes
  6. promote to a real server (task api:run) when the browser runtime stops being enough

Contract shape ​

ts
import type { Contract, Endpoint } from "@maxanstey-meridian/rivet-ts";

export interface UserDto {
  id: string;
  name: string;
  email: string;
}

export interface GetUserParams {
  id: string;
}

export interface UsersContract extends Contract<"UsersContract"> {
  GetUser: Endpoint<{
    method: "GET";
    route: "/users/{id}";
    params: GetUserParams;
    response: UserDto;
  }>;
}

Scaffold the app:

bash
pnpm exec rivet-ts scaffold-mock --entry ./contracts.ts --out ./myapp
cd ./myapp
task install
task dev

Then use the typed client (an openapi-fetch instance checked against the generated schema.d.ts):

ts
import { client } from "@myapp/contracts";

const { data, error } = await client.GET("/users/{id}", {
  params: { path: { id: "usr_123" } },
});

scaffold-mock emits the workspace with bootstrap artifacts already in place. After contract changes, task generate re-runs the pipeline: contract entry → api.contract.json (internal IR) → openapi.json (Rivet binary) → schema.d.ts (openapi-typescript).

Pages ​