typing api #18

Open
opened 2026-04-13 07:35:07 +00:00 by jkeffects · 0 comments
Owner

https://jakerobins.com/blog/using-zod-to-provide-typesafe-express-requests

better param parsing:

interface Params {
  postId: string;
}

interface Body {
  title: string;
  content: string;
}

interface Query {
  draft?: 'true' | 'false';
}

app.post(
  '/posts/:postId',
  (req: Request<Params, any, Body, Query>, res: Response) => {
    const { postId } = req.params;
    const { title, content } = req.body;
    const { draft } = req.query;

    res.json({ postId, title, content, draft });
  }
);
https://jakerobins.com/blog/using-zod-to-provide-typesafe-express-requests better param parsing: ```ts interface Params { postId: string; } interface Body { title: string; content: string; } interface Query { draft?: 'true' | 'false'; } app.post( '/posts/:postId', (req: Request<Params, any, Body, Query>, res: Response) => { const { postId } = req.params; const { title, content } = req.body; const { draft } = req.query; res.json({ postId, title, content, draft }); } ); ```
Sign in to join this conversation.
No labels
bug
feature
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
FF-Admin/ff-admin-core-server#18
No description provided.