Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Learn the Basics  ›  Lesson

URLs, Path and Query Parameters

URL, Query & Path Parameters 12 minPath parameters identify which resource you mean, while query parameters change how you want to see it, such as filtering, sorting or paging.

URLs, Path and Query Parameters

A member wants "books by Tolkien, newest first, 20 at a time". Another wants "book 42". Both requests go to BookNook, but they carry their details in different parts of the URL. Put each detail in the right part and your API reads like a sentence; put it in the wrong part and every caller has to guess.

The rule

The path says which thing; the query says how you want it.

A URL breaks into named pieces:

https://api.booknook.example/v1/books/42?fields=title,author#reviews
└─┬─┘   └─────────┬────────┘└─────┬────┘└─────────┬────────┘└───┬──┘
scheme          host            path            query       fragment
  • Path parameters are the variable segments of the path. In /v1/books/42, the 42 is a path parameter. It identifies a resource: without it, you are pointing at a different thing.
  • Query parameters come after ? as key=value pairs joined by &. They shape the answer: filter, sort, page, choose fields. Leave them out and you still reach the same resource, just a default view of it.
  • The fragment after # never reaches the server; the browser keeps it.
GET /v1/books?author=tolkien&sort=-published&limit=20
GET /v1/members/7/loans?status=active

Special characters must be percent-encoded: a space becomes %20, and a literal & inside a value becomes %26, so it is not mistaken for a separator. A search for "war & peace" is sent as q=war%20%26%20peace.

The shortcut

Ask one question of each detail: "If I remove it, am I pointing at a different thing?" Yes → path. No, just a different view → query.

Placing "active loans of member 7, oldest first"Step 1 of 4
  1. Member 7

    Without it you would be looking at someone else's loans. It identifies → path: /members/7.

Result: /v1/members/7/loans?status=active&sort=due. The trap is the reverse: /v1/books/sort/newest makes "sorting" look like a resource.

Drills

Answer fast — trust the rule.

quick drill

In /v1/books/42?fields=title, which part is a path parameter?

quick drill

Where should "only books published after 2000" go?

quick drill

What does the server receive for https://api.booknook.example/v1/books#top?

quick drill

A caller searches for the title R&D Handbook. How should the & travel inside q=?

Remember

  • The path says which thing; the query says how you want it.
  • Shortcut: "if I remove it, is it a different thing?" Yes → path, no → query.
  • Trap: verbs or sort orders in the path, and unencoded &, ? or spaces in values.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainPath or query?

Design the URL for 'the returned loans of member 7, newest first'. Explain why each detail goes in the path or the query.