A REST API is a way for two programs to talk over the internet using ordinary web addresses and simple requests. You send a request to a URL, name the action you want, and get back data, usually in JSON. Everything else in REST builds on that one loop, so understanding the request and the response is most of the work.

The rest depends on one thing: REST is a style, not a strict standard. Different APIs follow it loosely or strictly, so you learn the conventions and then read each API's own documentation.

Requests, Responses, and the Four Verbs That Do the Work

A request has four parts. The method says what you want to do. The URL says what you want to do it to. The headers carry information about the request. The body carries data, and only some requests have one.

REST maps four common verbs onto four actions. Learn these and you can read most API documentation.

MethodActionExample URL
GETRead data/books/42
POSTCreate something new/books
PUTReplace an existing item/books/42
DELETERemove an item/books/42

A GET request has no body. You are only asking, not sending. POST and PUT carry the data in the body. DELETE usually carries nothing. There is also PATCH, which changes only the fields you send instead of replacing the whole item.

REST calls things resources. A resource is usually a noun in the URL, like books or users. The verb is the method, not part of the address. So you use DELETE /books/42, not GET /deleteBook?id=42. That separation is the core idea.

Status Codes Tell You What Happened

Every response starts with a three-digit status code. You do not need to memorise hundreds. You need the families.

  • 200 means the request worked. 201 means something was created.
  • 400 means the request was malformed, usually a missing field or bad syntax.
  • 401 means you are not authenticated. 403 means you are authenticated but not allowed.
  • 404 means the resource does not exist.
  • 500 means the server failed, and the problem is not on your side.

Read the first digit and you already know who to fix. A 4xx is usually your request. A 5xx is the server. That single rule saves a lot of wasted debugging.

Reading and Creating One Record

Say a library API stores books. To read book 42, you send GET /books/42 with a header saying you accept JSON. The response might look like this:

{
  "id": 42,
  "title": "The Quiet Year",
  "author": "A. Reader",
  "available": true
}

To add a book, you send POST /books with a JSON body holding the fields the API requires, here a title and an author. You do not send an id. The server assigns it and returns 201 with the new record, including the id it chose. That is why the create response matters: it tells you the address of what you just made, often in a Location header.

To change availability, use PATCH /books/42 with a body of just {"available": false}. To remove the book, use DELETE /books/42. A 204 response with an empty body is the normal success reply to a delete.

Authentication, Keys, and What Never Goes in a URL

Most real APIs ask you to identify yourself. The common pattern is a token sent in a request header, usually an Authorization header. You get the token from the API's dashboard or a login endpoint, and you attach it to every request.

Treat a token like a password. Do not put it in a URL, where it ends up in logs and browser history. Do not commit it to shared code. If a key leaks, revoke it and issue a new one.

Rate limits also matter. APIs usually cap how many requests you can send in a period and reply with 429 when you go over. Read the limit in the docs and slow your loop down rather than retrying in a tight burst.

Testing a Call Safely Before You Build

Never begin by wiring an API into a working program. Test one call by hand first.

  1. Find the base URL and one example request in the documentation.
  2. Send a simple GET with your token in the header.
  3. Check the status code before you look at the body.
  4. Confirm the shape of the JSON matches the docs.
  5. Try one error case, such as a made-up id, and confirm you get a 404.

A tool that lets you send requests by hand is enough. Many APIs also offer a sandbox or test mode that does not touch real data, so use it while you learn. Once a call works by hand, copy the exact method, URL, headers and body into your code.

When REST Is the Wrong Fit

REST suits request-and-response work: fetch a list, save a record, look up a value. It is a poor match for live updates that push to you the moment something changes. For that, APIs often use a websocket or server-sent events. You will see those named in the same documentation.

One more rule of thumb: if you can describe the task as a noun plus one of the four verbs, REST will work. If you need many small updates per second, check the docs for something else.

The last habit is the most useful one. When a call fails, read the status code, then read the error body, which often names the exact field that is wrong. APIs usually tell you what went wrong if you slow down enough to read the reply.