In this lesson you will
- Design resource URLs and map actions to methods and status codes
- Use query strings for filtering and pagination, and nested URLs for relations
- Send and receive JSON correctly and avoid its data traps
Resources and URLs
A resource is a thing your API manages: a user, an order, a to-do item. Give each kind one collection URL with a plural noun, /todos, and each item a URL with its id, /todos/1. Relations become nested paths: /users/1/todos means the to-dos that belong to user 1. Keep verbs out of URLs. /getTodos, /createOrder and /deleteUser?id=5 repeat what the method already says and make every API different.
The query string is for options on a collection. /todos?userId=1&_limit=3 asks for user 1’s items, three at most; a shop API might use ?category=spices&sort=price&page=2. JSONPlaceholder names its paging option _limit; other APIs use limit, per_page or a cursor. Whatever you choose, keep one style across the whole API, document it, and set a sensible maximum so nobody can request a million rows at once.
Console
- Console messages, errors, form data and clicked links appear here.
This printed "Leanne Graham has these tasks:" and the same three titles as the curl output, each with [ ]. The second URL is built from the id of the first answer, which is how a client walks a REST API.
[
{
"userId": 1,
"id": 1,
"title": "delectus aut autem",
"completed": false
},
{
"userId": 1,
"id": 2,
"title": "quis ut nam facilis et officia qui",
"completed": false
},
{
"userId": 1,
"id": 3,
"title": "fugiat veniam minus",
"completed": false
}
][
{
"userId": 1,
"id": 1,
"title": "delectus aut autem",
"completed": false
},
{
"userId": 1,
"id": 2,
"title": "quis ut nam facilis et officia qui",
"completed": false
}
]Both URLs return the same kind of data in two ways: as a filter on the whole collection and as the collection that belongs to one user. Many APIs offer both.
Sign in free to read the full lesson
You are reading the free preview. Create a free account (it takes one minute, no password) to unlock the rest of this lesson and track your progress.
Unlocks after sign-in:
- 2 more sections with live code examples
- Common mistakes to avoid
- Hands-on coding exercise with automatic checks
- Practice quiz and the graded lesson test
Free forever. No card, no paywall.
Questions people ask
Should REST URLs use plural or singular nouns?
Plural is the most common convention: /todos for the list and /todos/1 for one item, so the same word works for both. What matters most is using one style everywhere in the API.
How should an API report validation errors?
Answer 400 or 422 with a JSON body that lists each problem and the field it belongs to. RFC 9457 defines a standard shape, application/problem+json, with fields such as type, title, status and detail.
How do I version a REST API?
The simplest way is a prefix such as /v1/todos, changed only for breaking changes. Adding new optional fields does not need a new version, but removing or renaming fields does.
Can JSON contain Arabic text?
Yes. JSON is Unicode text, normally sent as UTF-8, so Arabic works as is: {"name": "سوق الذهب"}. Make sure the response says charset=utf-8; some tools escape it as \u0633..., which parses to the same text.
What is the difference between REST and a RESTful API?
REST is the architectural style described by Roy Fielding in 2000; "RESTful" describes an API that follows it. In daily use both words mean an HTTP API built around resources, methods and status codes, as in this lesson.
Sources
Facts in this lesson were checked against these official pages on 29 November 2026.
- MDN: Working with JSON
- MDN: JSON.stringify()
- JSONPlaceholder guide
- RFC 8259: The JSON Data Interchange Format
- RFC 9457: Problem Details for HTTP APIs
Code examples stay in English and run in a sandbox on your device. If you spot a mistake, tell us through the contact page.