Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ts-rest/open-api

Package Overview
Dependencies
Maintainers
1
Versions
117
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ts-rest/open-api - npm Package Compare versions

Comparing version 3.17.0 to 3.18.0

4

package.json
{
"name": "@ts-rest/open-api",
"version": "3.17.0",
"version": "3.18.0",
"dependencies": {

@@ -10,3 +10,3 @@ "@anatine/zod-openapi": "^1.12.0",

"zod": "^3.0.0",
"@ts-rest/core": "3.17.0"
"@ts-rest/core": "3.18.0"
},

@@ -13,0 +13,0 @@ "typedoc": {

@@ -28,16 +28,56 @@ # ts-rest

ts-rest provides an RPC-like client side interface over your existing REST APIs, as well as allowing you define a _separate_ contract implementation rather than going for a 'implementation is the contract' approach, which is best suited for smaller or simpler APIs.
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.
If you have non typescript consumers, a public API, or maybe want to add type safety to your existing REST API? ts-rest is what you're looking for!
### Features
## Features
- End to end type safety 🛟
- Magic RPC-like API 🪄
- Tiny bundle size 🌟 (1kb!)
- RPC-like client side interface 📡
- [Tiny bundle size 🌟](https://bundlephobia.com/package/@ts-rest/core) (1kb!)
- Well-tested and production ready ✅
- No Code Generation 🏃‍♀️
- Zod support for body parsing 👮‍♀️
- Zod support for runtime type checks 👮‍♀️
- Full optional OpenAPI integration 📝
### Super Simple Example
Easily define your API contract somewhere shared
```typescript
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:
```typescript
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:
```typescript
const result = await client.getPosts({
query: { skip: 0, take: 10 },
// ^-- Fully typed!
});
```
## Quickstart

@@ -44,0 +84,0 @@

import { AppRouter } from '@ts-rest/core';
import { InfoObject, OpenAPIObject } from 'openapi3-ts';
/**
*
* @param options.jsonQuery - Enable JSON query parameters, [see](/docs/open-api#json-query-params)
* @returns
*/
export declare const generateOpenApi: (router: AppRouter, apiDoc: Omit<OpenAPIObject, 'paths' | 'openapi'> & {

@@ -4,0 +9,0 @@ info: InfoObject;

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