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, the42is a path parameter. It identifies a resource: without it, you are pointing at a different thing. - Query parameters come after
?askey=valuepairs 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=activeSpecial 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.