API Fundamentals Course
API Fundamentals
/
Beginner

Path Parameters

Definition

Variables embedded directly into the core structure of the URL path itself, used to identify a specific, unique resource.

Explain Like I'm New

Query params (`?id=5`) are for optional filters. Path params (`/users/5`) are for pointing at one exact, specific thing. It's the difference between asking 'Show me all users who happen to have the ID of 5' vs 'Take me exactly to User 5's house'.

Real World Example

Visiting a GitHub profile: `github.com/torvalds`. The word 'torvalds' is a path parameter. The server extracts it and searches for a user named Linus Torvalds.

Common Use Cases

  • •Fetching single records
  • •RESTful resource targeting

Interactive Example

Loading...
Console output will appear here...

Interview Questions

basic

  • In the URL path `/users/:id/posts`, what does the colon (`:`) represent?

intermediate

  • When designing an API to fetch a specific user, should you use `GET /users?id=123` or `GET /users/123`?

Flash Cards

Question

What does colon mean?

Click to reveal answer
Answer

It is standard framework syntax (used in Express, Next.js, React Router) indicating that the segment is a dynamic variable, not a literal string.

Question

Which design?

Click to reveal answer
Answer

You should use `GET /users/123` (Path parameter). According to REST principles, fetching a specific, unique resource should be done via the path. Query parameters should be reserved for filtering collections.