Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

RPC-like client, contract, and server implementation for a pure REST API

License

NotificationsYou must be signed in to change notification settings

ts-rest/ts-rest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Incrementally adoptable RPC-like client and server helpers for a magical end to end typed experience 🪄

GitHub Repo starsLicenseBundle 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 officialQuickstart Guide 👈

Super Simple Example

Easily define your API contract somewhere shared

constcontract=c.router({getPosts:{method:'GET',path:'/posts',query:z.object({skip:z.number(),take:z.number(),}),// <-- Zod schemaresponses:{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:

constrouter=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:

constresult=awaitclient.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 officialQuickstart 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.

Star History Chart
Join us on Discord for help, feedback, and discussions!


Discord Shield
Powered by Vercel

About

RPC-like client, contract, and server implementation for a pure REST API

Topics

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Contributors81


[8]ページ先頭

©2009-2025 Movatter.jp