A REST API request is a message your client sends over HTTP to a server, asking it to do something with a resource identified by a URL. The four parts are the method (GET, POST, PUT, PATCH, DELETE), the URL, the headers, and an optional body. What you can safely put in each part depends on one thing: whether the request only reads data or also changes it.

The Method Decides the Action

The method is a single word at the start of the request line, and it tells the server what kind of operation you intend. GET retrieves a resource and should never change anything on the server. POST creates a new resource under a collection. PUT replaces a resource in full. PATCH updates only the fields you send. DELETE removes a resource. HEAD works like GET but returns only headers, which is useful for checking whether something exists without downloading it.

These are conventions rather than hard rules, but servers and caches rely on them. If a GET request changes data, a cache or a browser prefetch can trigger that change without you meaning to. Keep GET safe and repeatable, and put every change behind POST, PUT, PATCH, or DELETE.

Methods also carry an expectation about repetition. GET, PUT, and DELETE should give the same result whether you send them once or five times. POST typically does not: sending it twice usually creates two records. That is why forms and payment calls often carry a unique key in the header, so the server can spot a repeat and ignore it.

Anatomy of a Real Request

A request is plain text on the wire, and every line has a job.

  • Request line: the method, the path, and the HTTP version, such as GET /v1/users/42 HTTP/1.1.
  • Host: the domain, so one server can answer for several sites.
  • Authorization: a token or key proving who you are, usually sent as Authorization: Bearer <token>.
  • Accept: the format you want back, such as application/json.
  • Content-Type: the format of the body you are sending, used on POST, PUT, and PATCH.
  • Body: the data itself, usually JSON, and empty on a GET.

Here is a complete POST that creates a user. Real numbers make the shape easier to remember.

  1. Method and path: POST /v1/users
  2. Headers include Content-Type: application/json and Authorization: Bearer abc123.
  3. Body is {"name":"Sam","age":34}.
  4. The server replies with status 201 Created, a Location header pointing at /v1/users/42, and the saved record.

The 201 tells you a new thing now exists. The Location header tells you where, so you never have to guess the new ID. A 200 with the same body would be ambiguous: it could mean updated or unchanged, which is why 201 exists.

Status Codes You Will Actually See

The first digit groups the reply. 2xx means success, 3xx means a redirect or cached copy, 4xx means your request was faulty, and 5xx means the server failed. Reading the exact code saves guesswork.

  • 200 OK: the request worked and the body holds the result.
  • 201 Created: a new resource exists; check Location.
  • 204 No Content: success with nothing to return, common after DELETE.
  • 400 Bad Request: the body is malformed or a field is missing.
  • 401 Unauthorized: no valid credentials were sent.
  • 403 Forbidden: you are authenticated but not allowed.
  • 404 Not Found: that URL or ID does not exist.
  • 429 Too Many Requests: you exceeded a rate limit; wait before retrying.
  • 500 Internal Server Error: the server broke; retrying the same request rarely helps.

The 401 versus 403 split trips up many people. 401 means the server does not know who you are. 403 means it knows and has decided you cannot do this. Fixing a 401 means checking the token; fixing a 403 means checking permissions or the account you are using.

Headers, Tokens, and Common Errors

Headers carry metadata the body cannot. Authentication most often goes in the Authorization header, not the URL. Putting a token in the query string is a real risk, because URLs appear in logs, browser history, and referrer headers.

A frequent misconception is that a token identifies a person forever. In practice, access tokens expire, often within about an hour, and a refresh token gets a new one. A 401 that appears after a quiet period usually means the token aged out, not that the account broke. Check the expiry before rewriting code.

The most common mistake is a wrong or missing Content-Type. Send JSON without Content-Type: application/json and many servers either reject the body with a 400 or treat it as empty. The mirror error is expecting JSON back but reading a plain-text error page from the server.

Another trap is encoding. IDs or search terms in the path must be URL-encoded, so a space becomes %20 and a slash inside a value becomes %2F. Skip this and a 404 appears for a resource that plainly exists.

Trying a Request Safely

Before building anything, send one small request by hand. Most languages ship a command-line client, and most APIs offer an interactive documentation page where you fill in fields and click send.

  1. Start with a GET that returns a list, such as GET /v1/users. No body, no risk of change.
  2. Add the base URL and the Authorization header. Confirm you get a 200.
  3. Pick one ID from the response and GET it directly, for example /v1/users/42. Confirm the fields match.
  4. Only then try a POST against a test environment, using a field like "name":"Test" that you can spot and delete.
  5. Read the full response, not just the status: headers, body, and any error message.

Work in a sandbox if the provider offers one. If not, create and then delete a single record you can identify by name. That keeps the test reversible and stops test data from piling up.

Retries, Rate Limits, and Pagination

Networks drop connections, so some retries are sensible. Retry only when the failure looks temporary: a timeout, a 429, or a 5xx. Never retry a 400 or a 401 unchanged, because the same faulty request will fail the same way.

For rate limits, wait and then try again rather than hammering the endpoint. If the response carries a header showing when you may retry, read it and wait that long. Add a short delay between attempts so the wait grows each time.

Lists are usually paged. A response may hold 20 items plus a cursor or a page number telling you where the next batch starts. Loop until the next link or cursor is empty, and set a stopping limit so a bug cannot loop forever.

Remember that labels, header names, and parameter names differ between APIs and between tool versions. When a field name looks unfamiliar, check that API's own documentation rather than assuming yours is wrong. One worked check: if a list call returns 20 items and a total of 47, two more pages remain.