Socket
Socket
Sign inDemoInstall

@ts-rest/nest

Package Overview
Dependencies
Maintainers
1
Versions
126
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ts-rest/nest

Nest server integration for @ts-rest


Version published
Weekly downloads
18K
decreased by-2.64%
Maintainers
1
Weekly downloads
ย 
Created
Source

ts-rest

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

langue typescript Github Workflow Status npm License Bundle Size Discord

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 interface ๐Ÿ“ก
  • Tiny bundle size ๐ŸŒŸ (1kb!)
  • Well-tested and production ready โœ…
  • No Code Generation ๐Ÿƒโ€โ™€๏ธ
  • Zod support for runtime type checks ๐Ÿ‘ฎโ€โ™€๏ธ
  • Full optional OpenAPI integration ๐Ÿ“

Super Simple Example

Easily define your API contract somewhere shared

const contract = c.contract({
  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(),
    }),
  },
});

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

const router = s.router(contract, {
  getPost: 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

Install the core package

yarn add @ts-rest/core
# Optional react-query integration
yarn add @ts-rest/react-query
# Pick your backend
yarn add @ts-rest/nest @ts-rest/express
# For automatic server OpenAPI gen
yarn add @ts-rest/open-api

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.

๐Ÿ‘‰ Read more on the official Quickstart Guide ๐Ÿ‘ˆ

Star History

Star History Chart

Contributors โœจ

Thanks goes to these wonderful people (emoji key):

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

๐Ÿ’ป

This project follows the all-contributors specification. Contributions of any kind welcome!

Keywords

FAQs

Package last updated on 10 Aug 2023

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with โšก๏ธ by Socket Inc