the documentation for zod-middleware gives this example:
export async function endpointCode(req: TypedRequestBody<typeof bodySchema>, res: Response) {
const typedBody = req.body;
return res.json(typedBody);
}
it give nice access to body through req.body
HOWEVER i need to have access to both QUERY and PARAMS (not body, it was just in the doc so i pasted it for reference). currently my router looks like this
exampleRouter.get("/:id/examples", processRequest({ params: FindExamplesParams, query: FindExamplesQuery }), findExamples);
How should the declaration of findExamples
function look like if i want to access both query and and params?
for just query or just params its easy:
export async function findSomething(req: TypedRequestQuery<typeof SomeQuery>, res: ...)
but what do i do for both?
zod-express-middleware
also includes TypedRequest
where you can pass the params, query, and body (in that order):
export async function findSomething(req: TypedRequest<typeof SomeParams, typeof SomeQuery>, res: ...) {
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments