@trpc/server 11.22.2-canary.7.c01346ec8 → 11.23.0

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.
Files changed (114) hide show
  1. package/README.md +0 -8
  2. package/dist/adapters/aws-lambda/index.cjs +1 -1
  3. package/dist/adapters/aws-lambda/index.d.cts.map +1 -1
  4. package/dist/adapters/aws-lambda/index.d.mts.map +1 -1
  5. package/dist/adapters/aws-lambda/index.mjs +1 -1
  6. package/dist/adapters/aws-lambda/index.mjs.map +1 -1
  7. package/dist/adapters/express.cjs +1 -1
  8. package/dist/adapters/express.mjs +1 -1
  9. package/dist/adapters/express.mjs.map +1 -1
  10. package/dist/adapters/fastify/index.cjs +3 -3
  11. package/dist/adapters/fastify/index.mjs +3 -3
  12. package/dist/adapters/fetch/index.cjs +1 -1
  13. package/dist/adapters/fetch/index.mjs +1 -1
  14. package/dist/adapters/next-app-dir.mjs.map +1 -1
  15. package/dist/adapters/next.cjs +1 -1
  16. package/dist/adapters/next.mjs +1 -1
  17. package/dist/adapters/next.mjs.map +1 -1
  18. package/dist/adapters/node-http/index.cjs +1 -1
  19. package/dist/adapters/node-http/index.mjs +1 -1
  20. package/dist/adapters/standalone.cjs +9 -3
  21. package/dist/adapters/standalone.d.cts +0 -1
  22. package/dist/adapters/standalone.d.cts.map +1 -1
  23. package/dist/adapters/standalone.d.mts +0 -1
  24. package/dist/adapters/standalone.d.mts.map +1 -1
  25. package/dist/adapters/standalone.mjs +9 -3
  26. package/dist/adapters/standalone.mjs.map +1 -1
  27. package/dist/adapters/ws.cjs +1 -1
  28. package/dist/adapters/ws.mjs +1 -1
  29. package/dist/asyncGeneratorDelegate-FcEJT04i.mjs.map +1 -1
  30. package/dist/codes-C9N0z0an.mjs.map +1 -1
  31. package/dist/getErrorShape-zlj81BiC.mjs.map +1 -1
  32. package/dist/http.cjs +1 -1
  33. package/dist/http.mjs +1 -1
  34. package/dist/initTRPC-RMeQIy9H.mjs.map +1 -1
  35. package/dist/{node-http-B5jkpWn7.mjs → node-http-ChhZEv1k.mjs} +2 -2
  36. package/dist/node-http-ChhZEv1k.mjs.map +1 -0
  37. package/dist/{node-http-BZ0HlzkC.cjs → node-http-X8RiQEuH.cjs} +1 -1
  38. package/dist/parseTRPCMessage-CJ4DJVBp.mjs.map +1 -1
  39. package/dist/{resolveResponse-b9D_SrLs.cjs → resolveResponse-CoGjFxK0.cjs} +8 -4
  40. package/dist/{resolveResponse-DH5L33sC.mjs → resolveResponse-DksrxZ2k.mjs} +9 -5
  41. package/dist/resolveResponse-DksrxZ2k.mjs.map +1 -0
  42. package/dist/unstable-core-do-not-import-B8epiErP.d.cts.map +1 -1
  43. package/dist/unstable-core-do-not-import-Dbo98mkh.d.mts.map +1 -1
  44. package/dist/unstable-core-do-not-import.cjs +1 -1
  45. package/dist/unstable-core-do-not-import.mjs +1 -1
  46. package/dist/unstable-core-do-not-import.mjs.map +1 -1
  47. package/dist/{ws-83TNWW-W.cjs → ws-7qWW7Uec.cjs} +2 -2
  48. package/dist/{ws-DJ2SSChC.mjs → ws-BYfo-HED.mjs} +3 -3
  49. package/dist/ws-BYfo-HED.mjs.map +1 -0
  50. package/package.json +9 -12
  51. package/skills/adapter-aws-lambda/SKILL.md +152 -134
  52. package/skills/adapter-express/SKILL.md +127 -113
  53. package/skills/adapter-fastify/SKILL.md +228 -136
  54. package/skills/adapter-fetch/SKILL.md +388 -111
  55. package/skills/adapter-standalone/SKILL.md +184 -94
  56. package/skills/auth/SKILL.md +327 -202
  57. package/skills/auth/references/client-cors.md +29 -0
  58. package/skills/caching/SKILL.md +58 -148
  59. package/skills/error-handling/SKILL.md +280 -174
  60. package/skills/middlewares/SKILL.md +320 -121
  61. package/skills/non-json-content-types/SKILL.md +149 -168
  62. package/skills/server-setup/SKILL.md +355 -253
  63. package/skills/server-setup/references/server-context.md +219 -0
  64. package/skills/server-setup/references/server-merging-routers.md +141 -0
  65. package/skills/server-setup/references/server-metadata.md +105 -0
  66. package/skills/server-setup/references/server-procedures.md +172 -0
  67. package/skills/server-setup/references/server-routers.md +123 -0
  68. package/skills/server-side-calls/SKILL.md +247 -152
  69. package/skills/service-oriented-architecture/SKILL.md +81 -177
  70. package/skills/subscriptions/SKILL.md +341 -297
  71. package/skills/subscriptions/references/client-links-httpSubscriptionLink.md +404 -0
  72. package/skills/subscriptions/references/client-links-wsLink.md +122 -0
  73. package/skills/subscriptions/references/server-websockets.md +297 -0
  74. package/skills/trpc-router/SKILL.md +156 -86
  75. package/skills/validators/SKILL.md +384 -128
  76. package/src/adapters/aws-lambda/getPlanner.ts +4 -3
  77. package/src/adapters/aws-lambda/index.ts +2 -1
  78. package/src/adapters/express.ts +1 -1
  79. package/src/adapters/next-app-dir/nextAppDirCaller.ts +4 -4
  80. package/src/adapters/next-app-dir/rethrowNextErrors.ts +1 -1
  81. package/src/adapters/next.ts +1 -1
  82. package/src/adapters/node-http/incomingMessageToRequest.ts +1 -1
  83. package/src/adapters/node-http/nodeHTTPRequestHandler.ts +1 -1
  84. package/src/adapters/node-http/types.ts +1 -1
  85. package/src/adapters/node-http/writeResponse.ts +1 -1
  86. package/src/adapters/standalone.ts +12 -6
  87. package/src/adapters/ws.ts +5 -5
  88. package/src/unstable-core-do-not-import/clientish/inferrable.ts +4 -1
  89. package/src/unstable-core-do-not-import/clientish/serialize.ts +4 -4
  90. package/src/unstable-core-do-not-import/error/TRPCError.ts +3 -3
  91. package/src/unstable-core-do-not-import/http/formDataToObject.ts +1 -1
  92. package/src/unstable-core-do-not-import/http/getHTTPStatusCode.ts +1 -1
  93. package/src/unstable-core-do-not-import/http/resolveResponse.ts +13 -2
  94. package/src/unstable-core-do-not-import/procedure.ts +5 -2
  95. package/src/unstable-core-do-not-import/procedureBuilder.ts +3 -2
  96. package/src/unstable-core-do-not-import/rootConfig.ts +2 -2
  97. package/src/unstable-core-do-not-import/router.ts +5 -2
  98. package/src/unstable-core-do-not-import/rpc/envelopes.ts +3 -2
  99. package/src/unstable-core-do-not-import/stream/jsonl.ts +2 -1
  100. package/src/unstable-core-do-not-import/stream/sse.types.ts +1 -1
  101. package/src/unstable-core-do-not-import/stream/utils/asyncIterable.ts +1 -1
  102. package/src/unstable-core-do-not-import/stream/utils/createDeferred.ts +1 -1
  103. package/src/unstable-core-do-not-import/stream/utils/disposable.ts +6 -6
  104. package/src/unstable-core-do-not-import/stream/utils/mergeAsyncIterables.ts +2 -2
  105. package/src/unstable-core-do-not-import/stream/utils/withPing.ts +3 -1
  106. package/src/unstable-core-do-not-import/transformer.ts +4 -1
  107. package/src/unstable-core-do-not-import/types.ts +3 -2
  108. package/src/unstable-core-do-not-import/utils.ts +1 -1
  109. package/src/vendor/standard-schema-v1/spec.ts +2 -2
  110. package/src/vendor/unpromise/unpromise.ts +1 -1
  111. package/bin/intent.js +0 -20
  112. package/dist/node-http-B5jkpWn7.mjs.map +0 -1
  113. package/dist/resolveResponse-DH5L33sC.mjs.map +0 -1
  114. package/dist/ws-DJ2SSChC.mjs.map +0 -1
@@ -1,63 +1,71 @@
1
1
  ---
2
2
  name: non-json-content-types
3
- description: >
4
- Handle FormData, file uploads, Blob, Uint8Array, and ReadableStream inputs in
5
- tRPC mutations. Use octetInputParser from @trpc/server/http for binary data.
6
- Route non-JSON requests with splitLink and isNonJsonSerializable() from
7
- @trpc/client. FormData and binary inputs only work with mutations (POST).
8
- type: core
9
- library: trpc
10
- library_version: '11.16.0'
3
+ description: Handle FormData, file uploads, Blob, Uint8Array, and ReadableStream inputs in tRPC mutations. Use octetInputParser from @trpc/server/http for binary data. Route non-JSON requests with splitLink and isNonJsonSerializable() from @trpc/client, since batching links send them as `{}`. FormData and binary inputs only work with mutations (POST) and skip the transformer. Keep Express or Next.js body parsers off tRPC routes.
11
4
  requires:
12
5
  - server-setup
13
6
  - links
14
7
  sources:
15
- - 'trpc/trpc:www/docs/server/non-json-content-types.md'
16
- - 'trpc/trpc:examples/next-formdata/'
8
+ - www/v11/docs/server/non-json-content-types.md
9
+ - www/v11/docs/server/adapters/express.md
10
+ metadata:
11
+ type: core
12
+ library: trpc
13
+ library_version: 11.23.0
17
14
  ---
18
15
 
19
- # tRPC -- Non-JSON Content Types
16
+ <!-- Generated from www/v11/docs/server/non-json-content-types.md by www/build/skills.ts. Edit the docs instead. -->
20
17
 
21
- ## Setup
18
+ # Content Types
22
19
 
23
- Server:
20
+ From https://trpc.io/docs/server/non-json-content-types
24
21
 
25
- ```ts
26
- // server/trpc.ts
27
- import { initTRPC } from '@trpc/server';
22
+ tRPC supports multiple content types as procedure inputs: JSON-serializable data, FormData, File, Blob, and other binary types.
28
23
 
29
- const t = initTRPC.create();
24
+ ## JSON (Default)
30
25
 
31
- export const router = t.router;
32
- export const publicProcedure = t.procedure;
33
- ```
26
+ By default, tRPC sends and receives JSON-serializable data. No extra configuration is needed — any input that can be serialized to JSON works out of the box with all links (`httpLink`, `httpBatchLink`, `httpBatchStreamLink`).
34
27
 
35
- ```ts
36
- // server/appRouter.ts
37
- import { octetInputParser } from '@trpc/server/http';
28
+ ```ts no-check
38
29
  import { z } from 'zod';
39
- import { publicProcedure, router } from './trpc';
40
-
41
- export const appRouter = router({
42
- uploadForm: publicProcedure
43
- .input(z.instanceof(FormData))
44
- .mutation(({ input }) => {
45
- const name = input.get('name');
46
- return { greeting: `Hello ${name}` };
47
- }),
48
- uploadFile: publicProcedure.input(octetInputParser).mutation(({ input }) => {
49
- // input is a ReadableStream
50
- return { valid: true };
30
+
31
+ export const t = initTRPC.create();
32
+ const publicProcedure = t.procedure;
33
+
34
+ export const appRouter = t.router({
35
+ hello: publicProcedure.input(z.object({ name: z.string() })).query((opts) => {
36
+ return { greeting: `Hello ${opts.input.name}` };
51
37
  }),
52
38
  });
39
+ ```
40
+
41
+ ## Non-JSON Content Types
42
+
43
+ In addition to JSON, tRPC can use FormData, File, and other binary types as procedure inputs.
44
+
45
+ ### Client Setup
46
+
47
+ > [!NOTE] Info
48
+ > While tRPC natively supports several non-JSON serializable types, your client may need a little link configuration to support them depending on your setup.
49
+
53
50
 
54
- export type AppRouter = typeof appRouter;
51
+ `httpLink` supports non-JSON content types out of the box — if you're only using this link, your existing setup should work immediately.
52
+
53
+ ```ts no-check
54
+ import { createTRPCClient, httpLink } from '@trpc/client';
55
+ import type { AppRouter } from './server';
56
+
57
+ createTRPCClient<AppRouter>({
58
+ links: [
59
+ httpLink({
60
+ url: 'http://localhost:2022',
61
+ }),
62
+ ],
63
+ });
55
64
  ```
56
65
 
57
- Client:
66
+ However, not all links support these content types. If you're using `httpBatchLink` or `httpBatchStreamLink`, you will need to include a `splitLink` and route requests based on the content type.
58
67
 
59
- ```ts
60
- // client/index.ts
68
+ ```ts no-check
61
69
  import {
62
70
  createTRPCClient,
63
71
  httpBatchLink,
@@ -65,84 +73,29 @@ import {
65
73
  isNonJsonSerializable,
66
74
  splitLink,
67
75
  } from '@trpc/client';
68
- import type { AppRouter } from '../server/appRouter';
76
+ import type { AppRouter } from './server';
69
77
 
70
- const url = 'http://localhost:3000';
78
+ const url = 'http://localhost:2022';
71
79
 
72
- const trpc = createTRPCClient<AppRouter>({
80
+ createTRPCClient<AppRouter>({
73
81
  links: [
74
82
  splitLink({
75
83
  condition: (op) => isNonJsonSerializable(op.input),
76
- true: httpLink({ url }),
77
- false: httpBatchLink({ url }),
84
+ true: httpLink({
85
+ url,
86
+ }),
87
+ false: httpBatchLink({
88
+ url,
89
+ }),
78
90
  }),
79
91
  ],
80
92
  });
81
93
  ```
82
94
 
83
- ## Core Patterns
84
-
85
- ### FormData mutation
86
-
87
- ```ts
88
- // server/appRouter.ts
89
- import { z } from 'zod';
90
- import { publicProcedure, router } from './trpc';
91
-
92
- export const appRouter = router({
93
- createPost: publicProcedure
94
- .input(z.instanceof(FormData))
95
- .mutation(({ input }) => {
96
- const title = input.get('title') as string;
97
- const body = input.get('body') as string;
98
- return { id: '1', title, body };
99
- }),
100
- });
101
- ```
102
-
103
- ```ts
104
- // client usage
105
- const form = new FormData();
106
- form.append('title', 'Hello');
107
- form.append('body', 'World');
108
-
109
- const result = await trpc.createPost.mutate(form);
110
- ```
111
-
112
- ### Binary file upload with octetInputParser
113
-
114
- ```ts
115
- // server/appRouter.ts
116
- import { octetInputParser } from '@trpc/server/http';
117
- import { publicProcedure, router } from './trpc';
118
-
119
- export const appRouter = router({
120
- upload: publicProcedure
121
- .input(octetInputParser)
122
- .mutation(async ({ input }) => {
123
- const reader = input.getReader();
124
- let totalBytes = 0;
125
- while (true) {
126
- const { done, value } = await reader.read();
127
- if (done) break;
128
- totalBytes += value.byteLength;
129
- }
130
- return { totalBytes };
131
- }),
132
- });
133
- ```
134
-
135
- ```ts
136
- // client usage
137
- const file = new File(['hello world'], 'test.txt', { type: 'text/plain' });
138
- const result = await trpc.upload.mutate(file);
139
- ```
95
+ If you are using `transformer` in your tRPC server, TypeScript requires that your tRPC client link defines `transformer` as well.
96
+ Use this example as a base:
140
97
 
141
- `octetInputParser` converts Blob, Uint8Array, and File inputs to a ReadableStream on the server.
142
-
143
- ### Client splitLink with superjson transformer
144
-
145
- ```ts
98
+ ```ts no-check
146
99
  import {
147
100
  createTRPCClient,
148
101
  httpBatchLink,
@@ -151,115 +104,143 @@ import {
151
104
  splitLink,
152
105
  } from '@trpc/client';
153
106
  import superjson from 'superjson';
154
- import type { AppRouter } from '../server/appRouter';
107
+ import type { AppRouter } from './server';
155
108
 
156
- const url = 'http://localhost:3000';
109
+ const url = 'http://localhost:2022';
157
110
 
158
- const trpc = createTRPCClient<AppRouter>({
111
+ createTRPCClient<AppRouter>({
159
112
  links: [
160
113
  splitLink({
161
114
  condition: (op) => isNonJsonSerializable(op.input),
162
115
  true: httpLink({
163
116
  url,
164
117
  transformer: {
118
+ // request - convert data before sending to the tRPC server
165
119
  serialize: (data) => data,
166
- deserialize: (data) => superjson.deserialize(data),
120
+ // response - convert the tRPC response before using it in client
121
+ deserialize: (data) => superjson.deserialize(data), // or your other transformer
167
122
  },
168
123
  }),
169
124
  false: httpBatchLink({
170
125
  url,
171
- transformer: superjson,
126
+ transformer: superjson, // or your other transformer
172
127
  }),
173
128
  }),
174
129
  ],
175
130
  });
176
131
  ```
177
132
 
178
- When using a transformer, the non-JSON httpLink needs a custom transformer that skips serialization for the request (FormData/binary cannot be transformed) but deserializes the response.
133
+ ### Server Setup
134
+
135
+ > [!NOTE] Info
136
+ > When a request is handled by tRPC, it takes care of parsing the request body based on the `Content-Type` header of the request.
137
+ > If you encounter errors like `Failed to parse body as XXX`, make sure that your server (e.g., Express, Next.js) isn't parsing the request body before tRPC handles it:
138
+ >
139
+ > - Express: see [Body parsers](https://trpc.io/docs/server/adapters/express#body-parsers).
140
+ > - Next.js Pages Router: turn off Next's body parser in the tRPC API route with `export const config = { api: { bodyParser: false } }`, as in our [FormData example](https://github.com/trpc/trpc/tree/main/examples/next-formdata).
179
141
 
180
- ## Common Mistakes
181
142
 
182
- ### [HIGH] Using httpBatchLink for FormData requests
143
+ #### `FormData` Input
183
144
 
184
- Wrong:
145
+ FormData is natively supported, and for more advanced usage you could also combine this with a library like [zod-form-data](https://www.npmjs.com/package/zod-form-data) to validate inputs in a type-safe way.
146
+
147
+ ```ts no-check
148
+ import { z } from 'zod';
185
149
 
186
- ```ts
187
- import { createTRPCClient, httpBatchLink } from '@trpc/client';
188
- import type { AppRouter } from '../server/appRouter';
150
+ export const t = initTRPC.create();
151
+ const publicProcedure = t.procedure;
189
152
 
190
- const trpc = createTRPCClient<AppRouter>({
191
- links: [httpBatchLink({ url: 'http://localhost:3000' })],
153
+ export const appRouter = t.router({
154
+ hello: publicProcedure.input(z.instanceof(FormData)).mutation((opts) => {
155
+ const data = opts.input;
156
+ return {
157
+ greeting: `Hello ${data.get('name')}`,
158
+ };
159
+ }),
192
160
  });
193
161
  ```
194
162
 
195
- Correct:
163
+ On the client, pass a `FormData` instance to the mutation:
196
164
 
197
- ```ts
198
- import {
199
- createTRPCClient,
200
- httpBatchLink,
201
- httpLink,
202
- isNonJsonSerializable,
203
- splitLink,
204
- } from '@trpc/client';
205
- import type { AppRouter } from '../server/appRouter';
165
+ ```ts no-check
166
+ const form = new FormData();
167
+ form.append('name', 'Bilbo');
206
168
 
207
- const url = 'http://localhost:3000';
169
+ const result = await client.hello.mutate(form);
170
+ ```
208
171
 
209
- const trpc = createTRPCClient<AppRouter>({
210
- links: [
211
- splitLink({
212
- condition: (op) => isNonJsonSerializable(op.input),
213
- true: httpLink({ url }),
214
- false: httpBatchLink({ url }),
215
- }),
216
- ],
172
+ For a more advanced code sample you can see our [example project here](https://github.com/juliusmarminge/trpc-interop/blob/66aa760141030ffc421cae1a3bda9b5f1ab340b6/src/server.ts#L28-L43)
173
+
174
+ #### `File` and other Binary Type Inputs
175
+
176
+ tRPC converts many octet content types to a `ReadableStream` which can be consumed in a procedure. Currently these are `Blob` `Uint8Array` and `File`.
177
+
178
+ ```ts no-check
179
+ import { octetInputParser } from '@trpc/server/http';
180
+
181
+ export const t = initTRPC.create();
182
+ const publicProcedure = t.procedure;
183
+
184
+ export const appRouter = t.router({
185
+ upload: publicProcedure.input(octetInputParser).mutation(async (opts) => {
186
+ const data = opts.input;
187
+ const reader = data.getReader();
188
+ let bytes = 0;
189
+ while (true) {
190
+ const { done, value } = await reader.read();
191
+ if (done) break;
192
+ bytes += value.byteLength;
193
+ }
194
+ return { bytes };
195
+ }),
217
196
  });
218
197
  ```
219
198
 
220
- FormData and binary inputs are not batchable; use `splitLink` with `isNonJsonSerializable()` to route them through `httpLink`.
199
+ On the client, pass a `File`, `Blob` or `Uint8Array` to the mutation:
221
200
 
222
- Source: www/docs/server/non-json-content-types.md
201
+ ```ts no-check
202
+ const file = new File(['hello world'], 'hello.txt', { type: 'text/plain' });
223
203
 
224
- ### [HIGH] Global body parser intercepting FormData before tRPC
204
+ await client.upload.mutate(file);
205
+ ```
225
206
 
226
- Wrong:
207
+ ## Common mistakes
227
208
 
228
- ```ts
229
- import * as trpcExpress from '@trpc/server/adapters/express';
230
- import express from 'express';
231
- import { appRouter } from './appRouter';
209
+ - **Using a query.** FormData and binary inputs are sent as the body of a `POST` request, so they only work with mutations: `httpLink` throws `FormData is only supported for mutations` for a query.
210
+ - **Sending them through a batching link.** `httpBatchLink`, `httpBatchStreamLink` and `wsLink` serialize inputs as JSON, which turns a `FormData` or `File` into `{}`, so input validation fails. Route them to `httpLink` with a [`splitLink`](https://trpc.io/docs/server/non-json-content-types#client-setup).
211
+ - **Transforming the request.** tRPC passes FormData and binary inputs to your procedure as they are, without your `transformer`. If you use one, give the non-JSON `httpLink` a transformer that leaves the request alone, as [shown above](https://trpc.io/docs/server/non-json-content-types#client-setup).
212
+ - **Letting your server parse the body first.** See [Server Setup](https://trpc.io/docs/server/non-json-content-types#server-setup).
232
213
 
233
- const app = express();
234
- app.use(express.json());
235
- app.use('/trpc', trpcExpress.createExpressMiddleware({ router: appRouter }));
236
- ```
214
+ ## Body parsers
215
+
216
+ tRPC parses request bodies itself, so tRPC routes don't need `express.json()`. If a body parser runs before tRPC anyway, tRPC uses the `req.body` it parsed, which works for JSON. For [FormData and binary inputs](https://trpc.io/docs/server/non-json-content-types) it depends on your Express version:
237
217
 
238
- Correct:
218
+ - **Express 5**: `express.json()` and `express.urlencoded()` leave other content types unread, so tRPC still reads them.
219
+ - **Express 4**: the parsers set `req.body` to `{}` on content types they skip, so tRPC receives `{}` instead of the form data or file.
220
+ - In both versions, a parser that reads the body you upload, like `express.raw()` for `application/octet-stream`, breaks binary inputs.
239
221
 
240
- ```ts
222
+ To be safe, register body parsers only on the routes that need them:
223
+
224
+ ```ts no-check title="server.ts"
241
225
  import * as trpcExpress from '@trpc/server/adapters/express';
242
226
  import express from 'express';
243
- import { appRouter } from './appRouter';
227
+ import { appRouter } from './router';
244
228
 
245
229
  const app = express();
246
- app.use('/api', express.json());
247
- app.use('/trpc', trpcExpress.createExpressMiddleware({ router: appRouter }));
248
- ```
249
-
250
- A global `express.json()` middleware consumes the request body before tRPC can read it; scope body parsing to non-tRPC routes only.
251
230
 
252
- Source: www/docs/server/non-json-content-types.md
231
+ app.use('/api', express.json()); // only for your own `/api/*` routes
232
+ app.post('/api/webhook', (req, res) => {
233
+ res.json({ received: req.body });
234
+ });
253
235
 
254
- ### [HIGH] FormData only works with mutations
236
+ app.use('/trpc', trpcExpress.createExpressMiddleware({ router: appRouter }));
255
237
 
256
- FormData and binary inputs are only supported for mutations (POST requests). Using them with `.query()` throws an error because queries use HTTP GET which cannot carry a request body.
238
+ app.listen(4000);
239
+ ```
257
240
 
258
- Source: www/docs/server/non-json-content-types.md
241
+ From https://trpc.io/docs/server/adapters/express#body-parsers
259
242
 
260
- ## See Also
243
+ ## Related skills
261
244
 
262
- - `server-setup` -- initTRPC, routers, procedures
263
- - `links` -- splitLink configuration for routing non-JSON requests
264
- - `validators` -- z.instanceof(FormData) for FormData validation
265
- - `adapter-express` -- Express-specific body parser considerations
245
+ - `server-setup` (https://trpc.io/docs/server/overview): `npx @tanstack/intent@latest load @trpc/server#server-setup`
246
+ - `links` (https://trpc.io/docs/client/links): `npx @tanstack/intent@latest load @trpc/client#links`