Final Project: Build a Typed Task API
Put every piece from this course together into one working, fully typed REST API for managing tasks.
Requirements
- Define a
TaskSchemawith Zod (id,title,done,priority, and at least one more field of your choice), deriveTaskwithz.infer. - Derive
CreateTaskSchema(omitid/done) andUpdateTaskSchema(fully partial,idomitted) fromTaskSchema, the way the earlier lesson did. - Implement all five endpoints against an in-memory array:
GET /tasks,GET /tasks/:id,POST /tasks,PATCH /tasks/:id,DELETE /tasks/:id. - Use the
validateBodymiddleware onPOSTandPATCH, returning400with the flattened Zod error on invalid input. - Use the
asyncHandlerwrapper on every route, and register a typederrorHandler(four-parameter,err: unknown) after all routes. - Return
404forGET/PATCH/DELETEon a task id that doesn't exist.
Stretch goals
- Add a
GET /tasks?priority=highfilter using a Zod schema to validate the query string too. - Add pagination (
?page=,?limit=) with sensible defaults. - Split schemas, routes, and the in-memory store into separate files, importing/exporting types and schemas between them.
- Write a small script (or use a REST client) that sends an intentionally invalid request and confirms you get a
400with a useful error message back.
Submit your repository link below when you are done, an instructor will review it before you can mark this lesson complete. Good luck! 🚀