Router Room
Challenge on lesson: Checkpoint: API Mechanic
CHALLENGE
Difficulty: intermediate+25 XP
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.
Press Submit to check your solution.
Back to lesson: Checkpoint: API Mechanic