· Cesar Camilo · Data Structures  · 3 min read

What is a REST API?

Introduction to the principles of REST APIs, how they work, and why they are the standard for communication on the modern web.

Introduction to the principles of REST APIs, how they work, and why they are the standard for communication on the modern web.

What is an API? An API (Application Programming Interface) is a set of rules and tools that allows different software applications to communicate with each other. Think of an API as a waiter in a restaurant.

You (the client) know what you want from the menu (the data or functionality), but you don’t know how the kitchen (the server) prepares the dish. The waiter (the API) takes your order, brings it to the kitchen, and brings your food back when it’s ready. It acts as an intermediary that abstracts away the complexity of the system.

In the digital world, APIs allow one application (like a mobile app) to request data or perform an action on another system (like a cloud server) without needing to know how that system is implemented internally.

So, What Does “REST” Mean? REST stands for REpresentational State Transfer. It’s a software architectural style, not a protocol or a standard, that defines a set of constraints for creating web services.

An API that follows the principles of REST is called a RESTful API. The main idea is that communication between the client and the server is handled through a limited set of operations using the HTTP protocol—the same one browsers use to load websites. REST has become the de facto standard for building APIs on the web due to its simplicity, scalability, and flexibility.

Key Principles of REST For an API to be considered RESTful, it must adhere to certain architectural principles.

  1. Client-Server Architecture The client (which requests information) and the server (which provides it) are separate. This separation of concerns allows both to evolve independently. For example, the mobile app team (client) can work without interfering with the team developing the logic on the server.

  2. Stateless Every request from a client to the server must contain all the information needed for the server to understand and process it. The server does not store any client state or context between requests. If you need authentication, for example, each request must include the authentication information (like a token). This improves scalability, as any server can handle any request.

  3. Uniform Interface This is the fundamental principle of REST and what sets it apart. It implies several things:

Identification of resources: Each resource (e.g., a user, a product) is identified with a unique URI (e.g., /api/users/123).

Manipulation through representations: The client interacts with a representation of the resource (commonly in JSON or XML format), not the resource itself.

Use of HTTP methods: Standard HTTP verbs are used to operate on resources.

How Does It Work in Practice? HTTP Methods REST leverages the methods that already exist in the HTTP protocol to define the actions to be performed on a resource. The most common are:

GET: To retrieve or read a resource.

POST: To create a new resource.

PUT / PATCH: To update an existing resource.

DELETE: To delete a resource.

Practical Example Imagine we have an API to manage a to-do list. The operations would look like this:

Using a RESTful API in this way creates a predictable and easy-to-understand system for developers, which has driven its massive adoption in the software industry.

Back to Notes

Related Posts

View All Posts »
Understanding Big O Notation

Understanding Big O Notation

A beginner-friendly guide to Big O notation for analyzing algorithm efficiency, with practical examples in Python.