03 / 07

What are route parameters

Difficulty: 4/10
URL parameters, middleware handling, routing design

Route parameters are named URL segments that are used to capture the values specified at their position in the URL. The captured values are populated in the req.params object, with the name of the route parameter specified in the path as their respective keys.

To define routes with route parameters, simply specify the route parameters in the path of the route as shown below.

Scenario Questions

0-2 years experience

  1. 1How would you define a route that captures a user ID from the URL in Express?
  2. 2If you have a route defined as app.get('/posts/:postId/comments/:commentId'), what will req.params contain when a request comes to /posts/12/comments/5?
  3. 3What happens if you define two routes with overlapping parameters, like '/users/:id' and '/users/profile'?

2-5 years experience

  1. 1You added a new route '/orders/:orderId' but requests to '/orders/status' are hitting the wrong handler. How would you debug and fix this?
  2. 2Explain why using a route parameter for a large numeric ID caused a performance issue in a high‑traffic endpoint, and what alternative you might consider.
  3. 3When refactoring a set of routes to use a router, how do you preserve access to the original route parameters across middleware?

5-8 years experience

  1. 1In a microservices architecture, you need to forward incoming requests with route parameters to downstream services while preserving them. What design considerations and potential pitfalls would you address?
  2. 2How would you implement validation and sanitization of route parameters in a way that scales across many routes without duplicating code?
  3. 3If you need to support optional route parameters and also maintain backward compatibility with older URL patterns, how would you design the routing layer?

8+ years experience

  1. 1Your organization is migrating from an Express monolith to a serverless platform. How would you handle existing route parameters to ensure minimal disruption and consistent API contracts?
  2. 2Discuss the trade‑offs of encoding multiple pieces of data into a single route parameter versus using query strings, especially regarding caching, CDN edge routing, and API versioning.
  3. 3When designing a shared routing library used across several teams, what conventions and abstractions would you enforce around route parameters to promote maintainability and avoid naming collisions?

Follow-up Questions

  • Can you walk me through how you’d test that the parameters are being parsed correctly?
  • What security concerns arise with user‑supplied route parameters?
  • How would you handle a situation where a parameter needs to be optional?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.