A REST API tutorial walks you through building an interface that lets programs exchange data over HTTP using standard methods and predictable URLs. A concrete example: a small book database might expose GET /books to list every book and GET /books/42 to fetch the single book whose ID is 42, with POST /books adding a new one. The rules are few, and the pattern repeats for every resource you add.
What Makes an API RESTful?
REST stands for Representational State Transfer. It is an architectural style, not a library or a protocol, and it describes how clients and servers should talk to each other. An API that follows the style treats everything as a resource with a unique address and uses the HTTP verbs you already know.
Five properties separate a REST API from an ad hoc web service:
- Resources are nouns. URLs name things like users, orders or readings. The method says what you want to do with them.
- Methods have fixed meanings.
GETreads,POSTcreates,PUTreplaces,PATCHpartially updates, andDELETEremoves. Every developer expects this contract. - Responses are stateless. Each request carries everything the server needs, such as a token. The server keeps no memory of the previous request, so any instance can answer any call.
- Representations are standard. JSON is the usual format, and images, CSV files or plain text are also valid representations of the same resource.
- Status codes carry meaning. The body of a response can be ignored and the client should still understand what happened from the code alone.
These properties matter because they let one API serve a mobile app, a website and a third-party integration simultaneously. When something breaks, the request itself is enough to reproduce and debug it.
How Do You Build a First REST Endpoint?
Pick a small, single-purpose resource for the first draft: a list of notes, a count of steps, a set of recipes. Keep the model to three or four fields so the shape of the data stays obvious while you learn the mechanics.
- Name the resource as a plural noun. Use
/notes, never/getAllNotesor/note_list. The verb is already supplied by the method. - Map the routes.
GET /noteslists all notes,GET /notes/{id}reads one,POST /notescreates one,PATCH /notes/{id}updates fields, andDELETE /notes/{id}removes one. A consistent set of five routes covers most resources. - Choose the identifiers. Return an opaque string or an integer that the client never parses. Let the server assign it so clients cannot collide on creation.
- Return the right status codes. Use
200for a successful read,201for a successful create together with aLocationheader pointing to the new resource,204for a delete with nothing to return,400for malformed input,404when the resource is missing, and500for a server fault. - Validate input before writing. Reject missing fields with a
400and a short error message that names the field. Never store unchecked input.
The first version should be boring. Get the routes, the status codes and the JSON shape right before adding authentication, pagination or caching. A clean skeleton is easier to extend than a clever one is to untangle.
What Should a Request and Response Actually Look Like?
Concrete bytes make the rules stick. Creating a note with POST /notes and a request body sends the resource description to the server:
{
"title": "Buy milk",
"done": false
}
The server replies with status 201 and echoes back the record including the server-assigned ID:
{
"id": "a7f3",
"title": "Buy milk",
"done": false,
"createdAt": "2026-12-05T09:00:00Z"
}
Follow with GET /notes/a7f3 and the same object returns with status 200. Ask for GET /notes/missing and the server answers 404 with a body such as {"error": "note not found"}.
Notice what the examples avoid. There are no verbs in the URL, no status information hidden inside the body, and no assumption that the client remembers anything. A client can script all of this with a single HTTP library, which is the point of the style.
REST API or Just an HTTP API?
The two terms are often used interchangeably, but they are not the same. HTTP APIs are the broader family: any service that exchanges data over HTTP belongs to it. A REST API is an HTTP API that also follows REST's resource-based conventions.
Where they diverge:
- Resource modelling. A REST API maps endpoints to nouns and relies on methods for actions. A plain HTTP API might expose
/createNoteor/notes/doUpdate, with the action in the path. - Predictability. A client that has seen one REST resource can guess the routes for the next. In a verb-based API, every route is a fresh discovery.
- Statelessness. REST requires the server to hold no session state between requests. A non-REST HTTP API may keep a server-side session tied to a cookie.
- Strictness. Strict REST purists add hypermedia links in responses so clients can navigate the API at runtime. Most practical APIs, often called pragmatic REST, skip this and document the routes instead.
The practical difference for a reader learning the concept is small at first: both are called with the same HTTP methods. What changes is the discipline of thinking in nouns. Adopting it early prevents a growing pile of one-off endpoints.
How Do You Test a REST API Without a Client App?
You do not need a mobile app or a front end to test an API. Any tool that sends HTTP requests will do: a command-line client, a graphical request builder, or your language's test framework. Start with the command line to see raw responses, then move the confirmed calls into automated tests.
- Send the create request and confirm the status is
201and the ID is returned. Save that ID. - Read the resource back with
GETand confirm every field you sent came back unchanged. - Send a deliberately invalid body with a missing field and confirm the
400response names the field. - Request a resource that does not exist and confirm a
404without a stack trace leaking internals. - Delete the resource, confirm
204, then read it again and confirm404. This round trip proves the full lifecycle.
Keep these five checks as a scripted test suite. They run in seconds and catch the regressions that break real integrations: a changed field name, a wrong code, a delete that quietly fails. Labels and menu names in request-building tools vary by version, so check the tool's documentation if a button is not where expected.
Signs Your API Calls Follow the REST Pattern
You do not need to memorise a specification to tell whether an API is behaving well. Look for these signs in any documentation or response you receive:
- Every URL is a plural noun, and action words appear only in methods, not in paths.
- The same resource is reachable by one predictable pattern: collection, then single item by ID.
- Status codes match the outcome, and errors use the
4xxrange for client mistakes and5xxfor server faults. - Error bodies contain a human-readable message and a stable error code you can branch on.
- Each request includes its own credentials, and no login session is required for a subsequent call.
- JSON field names stay consistent, usually the same case convention throughout.
- Lists are paginated with a documented parameter and a clear signal that more results exist.
One Misconception: REST Is a Format, Not a Protocol
A common mistake is reading REST as a specific data format or a wire protocol, like SOAP, that must be implemented with a particular library. REST defines constraints on how you structure the interaction, not the bytes on the wire. JSON is a convenient representation but not a requirement, and a REST API can return text, HTML or XML.
The correct fact: if your endpoints use nouns, HTTP methods with their standard meanings, stateless requests and meaningful status codes, you are working in the REST style, even if your responses are plain text. Tools and libraries help, but the style lives in your design choices.
Where to Take It Next
Once the five routes work and the test suite passes, add one improvement at a time and retest after each. Authentication comes first: put the token in the Authorization header, keep it out of URLs, and reject requests without it with a 401. Never place secrets in query strings, because URLs are logged by servers and proxies.
Pagination comes next for any growing collection. Return a limit and an offset, or a cursor, and include a link or field that tells the client another page exists. Then add filtering through query parameters such as /notes?done=false, and version the base path early, for example /v1/notes, so future breaking changes have a home.
Write down the contract in a shared description document as you go. A short reference of routes, request fields and responses saves every future client developer a round of guesswork. Review your five lifecycle tests whenever a route changes, and keep each endpoint small enough to describe in one sentence.