A REST API call is a request your app sends to a server over HTTP, using a URL, a method such as GET or POST, headers, and sometimes a body. The server replies with a status code and data, usually in JSON. The main condition is that the API must follow REST conventions, meaning resources are identified by URLs and actions are expressed by HTTP methods.

What a REST Call Contains

Every call has four parts. The method tells the server what to do. The URL names the resource. The headers carry metadata such as the content type and authentication. The body carries data for methods that send data, such as POST or PUT.

The method is the verb. GET reads a resource and should not change anything. POST creates a new resource. PUT replaces a resource entirely. PATCH changes part of it. DELETE removes it. If you use GET to delete something, you break the convention and tools may cache or retry the request in ways you did not intend.

The URL is the noun. A collection lives at a path such as /users, and one item lives at /users/42. Query strings narrow a collection, for example /users?role=admin&limit=20. Keep nouns in the path and put filters in the query string.

Headers describe the request. Content-Type: application/json tells the server the body is JSON. Accept: application/json tells it what you want back. An authorization header carries a token. These labels can differ slightly by tool, but the names above are long-standing.

Reading the Response

The status code is the server's short answer. Codes in the 200s mean success. A 201 means a resource was created. Codes in the 400s mean the request was wrong: 400 for a malformed request, 401 for missing or bad credentials, 403 for a valid user without permission, 404 for a resource that does not exist, 429 for too many requests. Codes in the 500s mean the server failed, and retrying later is reasonable.

The body usually holds JSON. A single item comes back as an object with fields. A collection comes back as an array, often wrapped with paging information such as a total count and a next-page link. Read the wrapper before you loop over the array, or you will iterate over the wrong level.

Check the status code before you parse the body. A 404 may return an HTML error page, and a JSON parser will fail on it with a confusing message. Branch on the code first, then parse.

An Example

Suppose you want the third page of orders for customer 42, 25 per page. You send a GET to /customers/42/orders?page=3&per_page=25 with an authorization header. The server replies 200 and a body like .

Do the arithmetic: 212 orders at 25 per page needs 9 pages, because 8 pages hold 200 and the ninth holds the remaining 12. Page 3 holds orders 51 through 75. If you request page 10, expect an empty array, not an error, on most APIs.

Now create an order. Send a POST to /customers/42/orders with Content-Type: application/json and a body such as {"item":"notebook","quantity":2}. A correct server replies 201 and includes a Location header pointing at the new order, for example /orders/913. Save that identifier; you need it for later reads and updates.

Authentication and Limits

Most APIs require a token. Send it in the authorization header, not in the URL, because URLs end up in logs and browser history. Treat the token like a password: keep it out of shared code and rotate it if it leaks.

Many APIs rate-limit calls. They return 429 when you exceed the limit and often include a header telling you how long to wait. Respect that wait. Retrying immediately makes the block longer. For transient 500s, retry a small number of times with a growing delay, for example 1 second, then 2, then 4.

Use pagination rather than asking for everything at once. A request for 10,000 records will time out or be refused. Walk the pages, or follow the next-page link the API provides.

Testing a Call Safely

  1. Start with a GET on a known collection, such as /users, to confirm the base URL and token work.
  2. Read the status code and the raw body before writing any parsing code.
  3. Try one item by identifier, such as /users/1, and confirm the shape matches the collection's items.
  4. Test a POST against a test account or sandbox, never production data.
  5. Check what happens on a bad request: send an invalid field and confirm you get a 400 with a useful message.
  6. Confirm pagination by requesting the last page and an out-of-range page.

Log the method, URL, status code and a request identifier for each call. When something fails, that record tells you which side is wrong.

Common Misconception

A common misconception is that REST is the same as JSON over HTTP. JSON is only the usual format. REST is the convention of resources, URLs and standard methods. An API can return XML and still be RESTful, and an API can return JSON without following REST at all.

Another trap is assuming a 200 means the operation worked. Some APIs return 200 with an error field in the body. Read the documented contract, and check the body for an error flag when the API uses one.

When Calls Fail

If you get 401, the token is missing, expired or wrong. If you get 403, the token is valid but lacks permission for that resource. If you get 404, check the path and the identifier. If you get 422, the body is syntactically fine but a field is invalid, and the response usually names the field.

If the call works in a browser but not in your code, compare headers. Browsers add some automatically. Your code must add the content type and authorization explicitly. If the call works once and then fails, suspect rate limits or an expired token.

Keep requests small and predictable. One resource per call, clear paths, standard methods. That habit makes failures easy to read and fixes quick to apply.