Skip to content

REST API Design and JSON: Resources, URLs, Methods, Filters and Common JSON Traps

NeedMyTools Academy

Sign in free to read the full lesson

Sign in or create a free account

Free forever. No card, no paywall.

REST is the most common way to organise a web API. It is a set of conventions, not a library: things are resources with their own URLs, and the HTTP method says what to do with them. When an API follows the conventions, a developer can guess GET /users/1/todos before reading the documentation. JSON is the format those resources travel in. This lesson uses JSONPlaceholder, a fake REST API, to show the full set of actions with real curl output, including the surprise that its writes are not saved. Then you send JSON from your browser and meet the JSON rules that silently drop or change your data.

Quick answer

In a REST API, URLs name resources with plural nouns (/todos, /todos/1, /users/1/todos) and methods name actions: GET lists or reads, POST to the collection creates (201), PUT replaces, PATCH updates part, DELETE removes. Filters, sorting and pagination go in the query string (?userId=1&_limit=3). Bodies are JSON with Content-Type: application/json. JSON has no dates, undefined or NaN: dates become strings, undefined properties disappear and NaN becomes null.

40 min read and practice · Content checked on 29 November 2026

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.

Try it: Following a relation: a user and their tasks
Code
ResultUpdates as you type
Console
  1. 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.

Example: A filtered list and a nested resource
Real output: curl "https://jsonplaceholder.typicode.com/todos?userId=1&_limit=3"
[
  {
    "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
  }
]
Real output: curl https://jsonplaceholder.typicode.com/users/1/todos?_limit=2
[
  {
    "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
Sign in or create a free account

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.

Code examples stay in English and run in a sandbox on your device. If you spot a mistake, tell us through the contact page.