Tony
Tony3w ago

I'm unable to make a GET request in postman. But able to make post requests

I get: expected object received undefined what could i be doing wrong? these are my routes, the problem is with testRoute:
const appRouter = router({
user: userRouter,
testRoute: publicProcedure
.input(
z.object({
name: z.string().nullish(),
}),
)
.output(
z.object({
greeting: z.string(),
}),
)
.query(({ input }) => {
return {
greeting: `hello ${input.name}`,
};
}),
});

export type AppRouter = typeof appRouter;
export { appRouter };
const appRouter = router({
user: userRouter,
testRoute: publicProcedure
.input(
z.object({
name: z.string().nullish(),
}),
)
.output(
z.object({
greeting: z.string(),
}),
)
.query(({ input }) => {
return {
greeting: `hello ${input.name}`,
};
}),
});

export type AppRouter = typeof appRouter;
export { appRouter };
Here's how i implemented in my expressJS app:
app.use(
"/api",
createExpressMiddleware({
router: appRouter,
createContext,
}),
);
app.use(
"/api",
createExpressMiddleware({
router: appRouter,
createContext,
}),
);
Postman GET Request: Please view image Using the latest versions of trpc/server
No description
1 Reply
jaronheard
jaronheard7d ago
issue here is that queries take input as a query parameter, not in the body. see https://trpc.io/docs/rpc
HTTP RPC Specification | tRPC
Methods Type mapping