Socket
Socket
Sign inDemoInstall

@ts-rest/nest

Package Overview
Dependencies
0
Maintainers
1
Versions
106
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ts-rest/nest

Nest server integration for @ts-rest


Version published
Maintainers
1
Weekly downloads
8,197
decreased by-2%

Weekly downloads

Readme

Source

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

Keywords

FAQs

Last updated on 17 Apr 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with โšก๏ธ by Socket Inc