Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ts-rest/ts-rest
RPC-like client, contract, and server implementation for a pure REST API
https://github.com/ts-rest/ts-rest
api fastify nestjs nextjs openapi react react-query rest rpc solid typescript
Last synced: 3 days ago
JSON representation
RPC-like client, contract, and server implementation for a pure REST API
- Host: GitHub
- URL: https://github.com/ts-rest/ts-rest
- Owner: ts-rest
- License: mit
- Created: 2022-07-23T11:23:01.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-09-10T07:15:48.000Z (3 months ago)
- Last Synced: 2024-10-29T09:33:09.279Z (about 1 month ago)
- Topics: api, fastify, nestjs, nextjs, openapi, react, react-query, rest, rpc, solid, typescript
- Language: TypeScript
- Homepage: https://ts-rest.com
- Size: 9.26 MB
- Stars: 2,381
- Watchers: 7
- Forks: 116
- Open Issues: 47
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Funding: FUNDING.yml
- Security: SECURITY.md
Awesome Lists containing this project
- awesome - ts-rest/ts-rest - RPC-like client, contract, and server implementation for a pure REST API (TypeScript)
- popular-dependents-lists - ts-rest/ts-rest - π 997 (Solid / ts-rest/ts-rest)
- awesome-zod - `ts-rest` - RPC-like client, contract, and server implementation for a pure REST API. (APIs and Servers)
- awesome-typesafe - ts-rest/ts-rest - RPC-like client, contract, and server implementation for a pure REST API. (**1. Libraries** / APIs)
- awesome-javascript - ts-rest - like client, contract, and server implementation for a pure REST API (Packages)
- awesome-javascript - ts-rest - like client, contract, and server implementation for a pure REST API (Packages)
README
# ts-rest
Incrementally adoptable RPC-like client and server helpers for a magical end to end typed experience πͺ
# 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 π### Super Simple Example
Easily define your API contract somewhere shared
```typescript
const contract = c.router({
getPosts: {
method: 'GET',
path: '/posts',
query: z.object({
skip: z.number(),
take: z.number(),
}), // <-- Zod schema
responses: {
200: c.type(), // <-- 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:
```typescript
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:
```typescript
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.
## Contributors β¨
MASSIVE Thanks to all of these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)), who have helped make ts-rest possible:
Youssef Gaber
π» π€ β οΈ
Per Hermansson
π π»
GrΓ©gory Houllier
π
Michael Angelo
π
Pieter Venter
π
Rifaldhi AW
π
Jonathan White
π» π
Max Brosnahan
π» π€
Oliver Butler
π» π€ π π π§
Adrian Barylski
π» π β οΈ
Neil A. Dobson
π»
Eric Do
π
Ben
π» π β οΈ
LW
π» π
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.