Design an HTTP Router

Medium · Low-Level Design · about 45 minutes

Asked at Atlassian.

Design the router of a web framework. add_route(path, handler) registers a path such as /users/list; call(path) returns the handler for a request path, or nothing. Then extend it: a * segment matches any single segment, and :id segments capture path parameters that are passed to the handler. When several routes match, the most specific wins.

Related guides