Skip to main content

Incrementally adoptable type-safety for your new and existing APIs

client.ts
import { initClient } from '@ts-rest/core';
import { contract } from './contract';

const client = initClient(contract, {
baseUrl: 'http://localhost:3000',
baseHeaders: {},
});

const response = await client.updatePost({
params: {
postId: '01ARZ3NDEKTSV4RRFFQ69G5FAV',
},
body: {
title: 'Post Title',
content: 'Post Body',
},
});
server.ts
import { createExpressEndpoints, initServer } from '@ts-rest/express';
import { contract } from './contract';

const app = express();
const prisma = new PrismaClient();

const s = initServer();
const router = s.router(contract, {
updatePost: async ({ body, params: { postId } }) => {
const post = await prisma.post.update({
where: { id: postId },
data: body,
});

return {
status: 200,
body: {
...post,
},
};
},
});

createExpressEndpoints(contract, router, app);

RPC-like Client With No Codegen

Fully typed RPC-like client, with no need for code generation!

API Design Agnostic

REST? HTTP-RPC? Your own custom hybrid? ts-rest doesn't care!

First Class DX

Less unnecessary builds in monorepos, instant compile-time errors, and instantly view endpoint implementations through your IDEs "go to definition"

Framework Agnostic

ts-rest comes with a whole host of support frameworks, including Express, Nest, Next and react-query!

Quick Dip

ts-rest was designed for and by TS-first teams who want to improve the stability and safety without a large investment into a new solution/tech (such as GraphQL), and need a simple, safe API with a focus on DX and adoption speed.

  • A seriously tiny type-safe wrapper around existing, battle-tested, established tech
  • An incrementally adoptable tool, for TS-first teams who care about stability + safety
  • No opinionated API structure, should be compatible with your existing structures

Don't just take our word for it

Give it a go

We've made a basic Stackblitz demo using a contract with Zod, client, and server - try and follow through the instructions to learn how ts-rest works!