# ts-rest/ts-rest

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/ts-rest-ts-rest).**

3,262 stars · 175 forks · TypeScript · mit

## Links

- GitHub: https://github.com/ts-rest/ts-rest
- Homepage: https://ts-rest.com
- awesome-repositories: https://awesome-repositories.com/repository/ts-rest-ts-rest.md

## Topics

`api` `fastify` `nestjs` `nextjs` `openapi` `react` `react-query` `rest` `rpc` `solid` `typescript`

## Description

ts-rest is a TypeScript toolkit for building type-safe APIs by defining a shared contract that connects client and server code. The core idea is to specify endpoints, methods, request and response shapes in a single contract, then use that contract to generate fully typed clients and enforce server implementations that match the contract at compile time.

The project provides a way to consume remote APIs through a client that infers request and response shapes from the shared contract, offering autocompletion and compile-time checks. On the server side, it enforces that handlers return correct status codes and response shapes as defined in the contract. Additionally, it includes runtime request validation against predefined schemas to catch mismatches before they reach business logic.

The documentation covers defining contracts, implementing servers, and consuming APIs with type safety, providing a complete workflow for end-to-end type safety in API development.

## Tags

### Software Engineering & Architecture

- [API Contract Definitions](https://awesome-repositories.com/f/software-engineering-architecture/api-contract-definitions.md) — Defines a shared contract specifying endpoints, methods, request and response shapes to enforce type safety across client and server. ([source](https://cdn.jsdelivr.net/gh/ts-rest/ts-rest@main/README.md))
- [Contract-First Server Implementations](https://awesome-repositories.com/f/software-engineering-architecture/contract-first-server-implementations.md) — Implements server handlers that enforce a shared contract, ensuring correct status codes and response shapes at compile time. ([source](https://cdn.jsdelivr.net/gh/ts-rest/ts-rest@main/README.md))
- [Request Validation](https://awesome-repositories.com/f/software-engineering-architecture/request-validation.md) — Validates incoming request data against predefined schemas to catch mismatches before they reach business logic. ([source](https://cdn.jsdelivr.net/gh/ts-rest/ts-rest@main/README.md))

### Web Development

- [Type-Safe API Clients](https://awesome-repositories.com/f/web-development/type-safe-api-clients.md) — Provides a fully typed client that infers request and response shapes from a shared contract for autocompletion and compile-time checks. ([source](https://cdn.jsdelivr.net/gh/ts-rest/ts-rest@main/README.md))
