Big news!Introducing Socket AI - ChatGPT-Powered Threat Analysis. Learn more
Socket
Log inDemoInstall

@ts-rest/nest

Package Overview
Dependencies
0
Maintainers
1
Versions
47
Issues
File Explorer

Advanced tools

@ts-rest/nest

Nest server integration for @ts-rest

    3.18.1latest
    GitHub

Version published
Maintainers
1
Weekly downloads
610
decreased by-26.33%

Weekly downloads

Readme

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.response<Post[]>(), // <-- OR normal TS types }, }, });

Fulfil the contract on your sever, 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({ 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

📖

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

Keywords

FAQs

Last updated on 04 Mar 2023

Did you know?

Socket installs a Github app to automatically flag issues on every pull request and report the health of your dependencies. Find out what is inside your node modules and prevent malicious activity before you update the dependencies.

Install Socket
Socket
support@socket.devSocket SOC 2 Logo

Product

  • Package Issues
  • 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