@rest-rpc/nest 0.1.0-beta.14 → 0.1.0-beta.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +82 -0
- package/package.json +3 -3
package/README.md
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# rest-rpc
|
|
2
|
+
|
|
3
|
+
REST-shaped APIs with function-shaped TypeScript.
|
|
4
|
+
|
|
5
|
+
Define your HTTP API once as a shared TypeScript contract, then derive typed
|
|
6
|
+
server handlers, fetch clients, openAPI documents, and more from it.
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
- Shared TypeScript contracts for HTTP APIs.
|
|
11
|
+
- Typed server handlers for Express, Hono, Fastify, NestJS, Next.js, and Fetch runtimes.
|
|
12
|
+
- Typed fetch client.
|
|
13
|
+
- Typed TanStack Query helpers.
|
|
14
|
+
- Typed WebSockets, streaming, non-JSON requests/responses.
|
|
15
|
+
- OpenAPI documents generated from the TypeScript contract.
|
|
16
|
+
- Standard Schema support.
|
|
17
|
+
|
|
18
|
+
## Minimal Example
|
|
19
|
+
|
|
20
|
+
Define a contract
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { router } from "@rest-rpc/core";
|
|
24
|
+
import { z } from "zod";
|
|
25
|
+
|
|
26
|
+
export const api = router({
|
|
27
|
+
todos: {
|
|
28
|
+
get: {
|
|
29
|
+
method: "GET",
|
|
30
|
+
path: "/todos/:id",
|
|
31
|
+
response: z.object({
|
|
32
|
+
id: z.string(),
|
|
33
|
+
title: z.string(),
|
|
34
|
+
}),
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Implement the contract on the server
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
const routes = router(api, {
|
|
44
|
+
todos: {
|
|
45
|
+
get({ id }) {
|
|
46
|
+
return getTodo(id);
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
registerRoutes(app, routes);
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
use the contract on the client with RPC-style function calls
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
import { initClient } from "@rest-rpc/core";
|
|
58
|
+
import { api } from "./contract";
|
|
59
|
+
|
|
60
|
+
const client = initClient(api, {
|
|
61
|
+
baseUrl: "https://api.example.com",
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const todo = await client.todos.get.fetch({
|
|
65
|
+
id: "todo_1",
|
|
66
|
+
});
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Documentation
|
|
70
|
+
|
|
71
|
+
Full documentation is available at [rest-rpc.dev](https://rest-rpc.dev)
|
|
72
|
+
|
|
73
|
+
## Packages
|
|
74
|
+
|
|
75
|
+
- [`@rest-rpc/core`](https://npmx.dev/package/@rest-rpc/core): API contract, client and openAPI generation.
|
|
76
|
+
- [`@rest-rpc/express`](https://npmx.dev/package/@rest-rpc/express): Express server adapter.
|
|
77
|
+
- [`@rest-rpc/fastify`](https://npmx.dev/package/@rest-rpc/fastify): Fastify server adapter.
|
|
78
|
+
- [`@rest-rpc/hono`](https://npmx.dev/package/@rest-rpc/hono): Hono server adapter.
|
|
79
|
+
- [`@rest-rpc/nest`](https://npmx.dev/package/@rest-rpc/nest): NestJS server adapter.
|
|
80
|
+
- [`@rest-rpc/next`](https://npmx.dev/package/@rest-rpc/next): Next.js adapter.
|
|
81
|
+
- [`@rest-rpc/fetch`](https://npmx.dev/package/@rest-rpc/fetch): Fetch runtime adapter
|
|
82
|
+
- [`@rest-rpc/tanstack-query`](https://npmx.dev/package/@rest-rpc/tanstack-query): TanStack Query adapter.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rest-rpc/nest",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.15",
|
|
4
4
|
"description": "NestJS adapter for serving rest-rpc contracts with typed HTTP routes.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"api-contract",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@rest-rpc/core": "0.1.0-beta.
|
|
39
|
-
"@rest-rpc/server": "0.1.0-beta.
|
|
38
|
+
"@rest-rpc/core": "0.1.0-beta.15",
|
|
39
|
+
"@rest-rpc/server": "0.1.0-beta.15"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@nestjs/common": "^11.0.0",
|