Path Parameter
ELI5 — The Vibe Check
A path parameter is a variable embedded directly in the URL path. Instead of '?id=5', you put the value right in the path: '/users/5'. It usually identifies a specific resource. Path params are cleaner-looking than query strings for resource IDs.
Real Talk
Path parameters are variable segments in a URL path used to identify specific resources in REST APIs. Defined with colons in route patterns (e.g., /users/:id), they're extracted by the server for processing. Unlike query strings, they're part of the resource identifier.
Show Me The Code
// Express.js path parameters
app.get('/users/:userId/posts/:postId', (req, res) => {
const { userId, postId } = req.params;
// GET /users/42/posts/7 → userId='42', postId='7'
res.json({ userId, postId });
});
// REST design convention:
// GET /products/123 → get product 123
// PUT /products/123 → update product 123
// DELETE /products/123 → delete product 123
When You'll Hear This
"Use a path parameter for the user ID in the REST endpoint." / "The path parameter
Related Terms
Query String
A query string is the part of a URL after the question mark.
REST (Representational State Transfer)
REST is a set of rules for how APIs should behave. Think of it as the etiquette guide for servers and clients talking to each other.
Route
A route is like a road sign that tells incoming requests where to go.
URL (Uniform Resource Locator)
A URL is the complete web address of something on the internet — the full 'how to get there' including the protocol, domain, path, and any query parameters...