Skip to main content

Router Room

Challenge on lesson: Checkpoint: API Mechanic

Write THREE functions. 1) matchRoute(pattern, method, path, method2) — pattern like "/tasks/:id"; return the params object when the method matches AND the path fits the pattern (segments align, :id captures one non-empty segment), else null. 2) orderMiddleware(names) — given a scrambled list containing "bodyParser", "auth", "logger", "errorBoundary", return the correct order: logger, bodyParser, auth, errorBoundary (errorBoundary wraps everything, so last). 3) statusFor(situation) — map: "created" => 201, "validation-failed" => 400, "not-logged-in" => 401, "not-allowed" => 403, "missing" => 404, "duplicate" => 409, "crashed" => 500.

Difficulty: intermediate

Back to lesson: Checkpoint: API Mechanic