@ts-rest/core
TypeScript icon, indicating that this package has built-in type declarations

3.51.0Β β€’Β PublicΒ β€’Β Published

ts-rest

Incrementally adoptable RPC-like client and server helpers for a magical end to end typed experience πŸͺ„

GitHub Repo stars License Bundle Size

Join us on Discord for help, feedback, and discussions!

Discord Shield

Introduction

ts-rest offers a simple way to define a contract for your API, which can be both consumed and implemented by your application, giving you end to end type safety without the hassle or code generation.

Features

  • End-to-end type safety πŸ›Ÿ
  • RPC-like client side API ⚑️
  • Small Bundle Size πŸ“‰
  • No Code Generation πŸƒβ€β™€οΈ
  • Zod support for runtime validation πŸ”’
  • Full optional OpenAPI integration πŸ“

πŸ‘‰ Start reading the official Quickstart Guide πŸ‘ˆ

Super Simple Example

Easily define your API contract somewhere shared

const contract = c.router({
  getPosts: {
    method: 'GET',
    path: '/posts',
    query: z.object({
      skip: z.number(),
      take: z.number(),
    }), // <-- Zod schema
    responses: {
      200: c.type<Post[]>(), // <-- OR normal TS types
    },
    headers: z.object({
      'x-pagination-page': z.coerce.number().optional(),
    }),
  },
});

Fulfill the contract on your server, with a type-safe router:

const router = s.router(contract, {
  getPosts: async ({ params: { id } }) => {
    return {
      status: 200,
      body: prisma.post.findUnique({ where: { id } }),
    };
  },
});

Consume the api on the client with a RPC-like interface:

const result = await client.getPosts({
  headers: { 'x-pagination-page': 1 },
  query: { skip: 0, take: 10 },
  // ^-- Fully typed!
});

Quickstart

Create a contract, implement it on your server then consume it in your client. Incrementally adopt, trial it with your team, then get shipping faster.

πŸ‘‰ Start reading the official Quickstart Guide πŸ‘ˆ

Contributors ✨

MASSIVE Thanks to all of these wonderful people (emoji key), who have helped make ts-rest possible:

Youssef Gaber
Youssef Gaber

πŸ’» πŸ€” ⚠️
Per Hermansson
Per Hermansson

πŸ“– πŸ’»
GrΓ©gory Houllier
GrΓ©gory Houllier

πŸ“–
Michael Angelo
Michael Angelo

πŸ“–
Pieter Venter
Pieter Venter

πŸ“–
Rifaldhi AW
Rifaldhi AW

πŸ“–
Jonathan White
Jonathan White

πŸ’» πŸ“–
Max Brosnahan
Max Brosnahan

πŸ’» πŸ€”
Oliver Butler
Oliver Butler

πŸ’» πŸ€” πŸ“– πŸš‡ 🚧
Adrian Barylski
Adrian Barylski

πŸ’» πŸ“– ⚠️
Neil A. Dobson
Neil A. Dobson

πŸ’»
Eric Do
Eric Do

πŸ“–
Ben
Ben

πŸ’» πŸ“– ⚠️
LW
LW

πŸ’» πŸ›
Andrew Vance
Andrew Vance

πŸ“–

Star History

Since our first commit in 2022 we've been growing steadily. We're proud of our progress and we're excited about the future.

Join us on Discord for help, feedback, and discussions!

Discord Shield

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
3.51.0
36,223latest
3.27.0-rc.01rc
3.26.0-rc3.01rc3
3.24.1-pre.11pre
3.49.0-beta.4
0beta

Version History

VersionDownloads (Last 7 Days)Published
3.51.0
36,223
3.50.0
2,348
3.49.4
51
3.49.3
4,997
3.49.2
1,297
3.49.1
0
3.49.0
35
3.49.0-beta.4
0
3.49.0-beta.3
0
3.49.0-beta.20
3.49.0-beta.10
3.48.12,747
3.48.00
3.47.0121
3.46.0418
3.45.212,842
3.45.18
3.45.0348
3.45.0-beta.10
3.45.0-beta.00
3.44.1704
3.44.0115
3.43.0413
3.42.00
3.41.2522
3.41.119
3.41.036
3.40.10
3.40.04
3.39.20
3.39.131
3.39.00
3.38.071
3.37.00
3.36.0640
3.36.0-beta.00
3.35.19
3.35.00
3.34.04
3.33.1156
3.33.06,888
3.32.00
3.31.0369
3.30.52,200
3.30.4551
3.30.30
3.30.2862
3.30.11,625
3.30.033
3.28.0146
3.27.0102
3.26.461
3.26.3296
3.27.0-rc.01
3.26.21
3.26.11
3.26.01
3.26.0-rc3.01
3.26.0-rc.01
3.25.124
3.25.01
3.24.1-pre.11
3.24.1-pre.01
3.24.01
3.24.0-rc.01
3.23.067
3.23.0-beta.01
3.22.1-pre.00
3.22.00
3.21.20
3.21.10
3.21.00
3.20.00
3.19.569
3.19.40
3.19.317
3.19.20
3.19.11
3.19.01
3.18.111
3.18.00
3.17.04
3.16.20
3.16.11
3.16.01
3.15.00
3.14.00
3.13.10
3.13.00
3.12.10
3.12.00
3.11.20
3.11.10
3.11.00
3.10.20
3.10.10
3.10.00
3.9.00
3.8.00
3.7.00
3.6.10
3.6.00
3.5.00
3.4.20
3.4.10
3.4.00
3.3.00
3.2.20
3.2.10
3.2.00
3.1.10
3.1.00
3.0.00
2.1.00
2.0.10
1.3.00
1.2.00
1.1.00
1.0.40
1.0.30
1.0.20
1.0.00
0.2.20
0.2.10
0.2.00
0.1.100
0.1.90
0.1.81
0.1.70
0.1.60
0.1.50
0.1.40
0.1.30
0.1.10
0.1.00

Package Sidebar

Install

npm i @ts-rest/core

Weekly Downloads

77,501

Version

3.51.0

License

MIT

Unpacked Size

107 kB

Total Files

22

Last publish

Collaborators

  • gabrola
  • oliverbutler