Open in TheBrain

REST API

A REST API (Representational State Transfer Application Programming Interface) is an architectural style that allows two computer systems to communicate over the internet. It acts as a translator, enabling a client (like a mobile app or a browser) to request data or trigger actions on a server using standard web protocols.

Because REST relies on the existing infrastructure of the internet—specifically HTTP—it is the most widely used standard for building web services.


Core Concepts of REST

To understand how a REST API works, it helps to look at its fundamental building blocks:

1. Resources and URIs

In REST, everything is considered a resource (a user, a product, an image, a statistical data point). Each resource is identified by a unique address called a URI (Uniform Resource Identifier) or an endpoint.

2. HTTP Methods (The Actions)

REST uses standard HTTP verbs to define what action you want to perform on a resource. This maps perfectly to standard CRUD (Create, Read, Update, Delete) operations:

HTTP MethodCRUD ActionDescriptionExample
GETReadRetrieves data from the server without modifying it.Get details of a player.
POSTCreateSubmits new data to the server to create a resource.Add a new player to the system.
PUTUpdateReplaces an entire existing resource with updated data.Update all fields of a specific player record.
PATCHUpdatePartially updates an existing resource (only changes specific fields).Update just a single field, like a player's team.
DELETEDeleteRemoves a specific resource from the server.Delete a player record.

3. Statelessness

This is a critical rule of REST. Stateless means that the server does not store any memory or "context" about past requests from a client.

Every single request sent from a client to a server must contain all the information needed to understand and process it (including authentication credentials, tokens, or parameters). The server treats every request as completely brand new.

4. Data Formats

While REST technically supports multiple formats (like XML, HTML, or plain text), JSON (JavaScript Object Notation) is overwhelmingly the most common format used today because it is lightweight and easy for both humans to read and machines to parse.


How a REST API Request & Response Looks

When a client communicates with a REST API, it sends a request and receives a response back.

The Request

A typical request includes:

The Response

The server processes the request and sends back a response containing:

JSON

// Example JSON response for a player data request
{
  "id": 27,
  "name": "Mike Trout",
  "position": "Outfielder",
  "status": "Active"
}

Why REST is So Popular