Skip to the workspace
Pebellslearn by building
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.

api design / URLs, Path and Query Parameters

Explore each scene at your own pace.

01 · The rule

The rule

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.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.