You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 19, 2024. It is now read-only.
We currently support adapters for [`Express`](http://expressjs.com/), [`Next.js`](https://nextjs.org/) & [`node:http`](https://nodejs.org/api/http.html).
69
+
We currently support adapters for [`Express`](http://expressjs.com/), [`Next.js`](https://nextjs.org/), [`Serverless`](https://www.serverless.com/) & [`node:http`](https://nodejs.org/api/http.html).
72
70
73
-
[`Fastify`](https://www.fastify.io/) & [`Serverless`](https://www.serverless.com/) soon™, PRs are welcomed 🙌.
71
+
[`Fastify`](https://www.fastify.io/) & more soon™, PRs are welcomed 🙌.
74
72
75
73
```typescript
76
74
importhttpfrom'http';
@@ -88,29 +86,29 @@ server.listen(3000);
88
86
```typescript
89
87
// client.ts
90
88
const res =awaitfetch('http://localhost:3000/say-hello?name=James', { method: 'GET' });
-`meta.openapi.method` is `GET`, `POST`, `PATCH`, `PUT` or `DELETE`.
108
105
-`meta.openapi.path` is a string starting with `/`.
109
106
-`meta.openapi.path` parameters exist in `input` parser as `ZodString`
110
107
111
108
Please note:
112
109
113
110
- Data [`transformers`](https://trpc.io/docs/data-transformers) are ignored.
111
+
- tRPC v9 `.interop()` routers are not supported.
114
112
- Trailing slashes are ignored.
115
113
- Routing is case-insensitive.
116
114
@@ -120,41 +118,43 @@ Procedures with a `GET`/`DELETE` method will accept inputs via URL `query parame
120
118
121
119
### Path parameters
122
120
123
-
A procedure can accept a set of inputs via URL path parameters. You can add a path parameter to any OpenAPI enabled procedure by using curly brackets around an input name as a path segment in the `meta.openapi.path` field.
121
+
A procedure can accept a set of inputs via URL path parameters. You can add a path parameter to any OpenAPI procedure by using curly brackets around an input name as a path segment in the `meta.openapi.path` field.
124
122
125
123
### Query parameters
126
124
127
125
Query & path parameter inputs are always accepted as a `string`, if you wish to support other primitives such as `number`, `boolean`, `Date` etc. please use [`z.preprocess()`](https://github.com/colinhacks/zod#preprocess).
const body =awaitres.json(); /* { greeting: 'Hello James!' } */
167
167
```
168
168
169
169
### Custom headers
@@ -172,32 +172,12 @@ Any custom headers can be specified in the `meta.openapi.headers` array, these h
172
172
173
173
## HTTP Responses
174
174
175
-
Inspired by [Slack Web API](https://api.slack.com/web).
176
-
177
175
Status codes will be `200` by default for any successful requests. In the case of an error, the status code will be derived from the thrown `TRPCError` or fallback to `500`.
178
176
179
177
You can modify the status code or headers for any response using the `responseMeta` function.
180
178
181
179
Please see [error status codes here](src/adapters/node-http/errors.ts).
182
180
183
-
```jsonc
184
-
{
185
-
"ok":true,
186
-
"data":"This is good"/* Output from tRPC procedure */
187
-
}
188
-
```
189
-
190
-
```jsonc
191
-
{
192
-
"ok":false,
193
-
"error": {
194
-
"message":"This is bad", /* Message from TRPCError */,
195
-
"code":"BAD_REQUEST", /* Code from TRPCError */
196
-
"issues": [...] /* (optional) ZodIssues[] from TRPCError */
197
-
}
198
-
}
199
-
```
200
-
201
181
## Authorization
202
182
203
183
To create protected endpoints, add `protect: true` to the `meta.openapi` object of each tRPC procedure. You can then authenticate each request with the `createContext` function using the `Authorization` header with the `Bearer` scheme.
@@ -221,6 +201,8 @@ const users: User[] = [
221
201
222
202
exporttypeContext= { user:User|null };
223
203
204
+
const t =initTRPC.context<Context>().meta<OpenApiMeta>().create();
205
+
224
206
exportconst createContext =async ({ req, res }):Promise<Context> => {
0 commit comments