doc
doc
Explore posts from servers
TtRPC
Created by doc on 7/4/2023 in #❓-help
trpc + fastify POST request not working
I have a trpc mutation like this:
create: publicProcedure
.input(z.object({ title: z.string() }))
.mutation(({ input, ctx }) => {
const id = db.posts.length + 1;
const post = { id, title: input.title };
db.posts.push(post);
return post;
}),
create: publicProcedure
.input(z.object({ title: z.string() }))
.mutation(({ input, ctx }) => {
const id = db.posts.length + 1;
const post = { id, title: input.title };
db.posts.push(post);
return post;
}),
I am trying to call it via HTTP:
curl --request POST \
--url http://localhost:2022/trpc/posts.create \
--header 'Content-Type: application/json' \
--data '{
"title": "hello"
}'
curl --request POST \
--url http://localhost:2022/trpc/posts.create \
--header 'Content-Type: application/json' \
--data '{
"title": "hello"
}'
it errors with:
"code": -32600, "data": { "code": "BAD_REQUEST", "httpStatus": 400, .....}
Not sure whats going on or why is it erroring. Any help is appreciated 🙂
"dependencies": {
"@fastify/websocket": "^7.1.2",
"@trpc/client": "^10.33.0",
"@trpc/server": "^10.33.0",
"fastify": "^4.13.0",
"node-fetch": "^3.3.1",
"superjson": "^1.12.4",
"tslib": "^2.5.0",
"ws": "^8.0.0",
"zod": "^3.0.0"
},
"dependencies": {
"@fastify/websocket": "^7.1.2",
"@trpc/client": "^10.33.0",
"@trpc/server": "^10.33.0",
"fastify": "^4.13.0",
"node-fetch": "^3.3.1",
"superjson": "^1.12.4",
"tslib": "^2.5.0",
"ws": "^8.0.0",
"zod": "^3.0.0"
},
3 replies
TtRPC
Created by doc on 1/27/2023 in #❓-help
TRPCClientError: Unexpected end of JSON input
Hey I am running into this issue when calling a mutateAsync in production in Vercel (the error does not appear in localhost dev mode).
TRPCClientError: Unexpected end of JSON input
My code base is so large that I am not sure where do I start to debug. Are there any best practices that I should follow to avoid this error? It is similar to this issue: https://github.com/trpc/trpc/discussions/1847#discussioncomment-4244990
19 replies