Skip to main content

Practice ยท 1 of 2

A router that says 404 vs 405 correctly

Implement Router with add(method, path, handler) and dispatch(method, path): - paths are /-separated segments; a segment like '{id}' matches exactly one segment of any value and binds it as a string param - dispatch returns handler(params) where params is a dict (empty for static routes) - if some pattern matches the path with a DIFFERENT method โ†’ raise RouterError(405, ...) - if no pattern matches the path at all โ†’ raise RouterError(404, ...) - RouterError carries .status

Difficulty: advanced

Back to lesson: Practice: Mini API Project