What are the primary principles of REST APIs?

A brief intro to a big topic.

What are the primary principles of REST APIs?
Photo by Walkator / Unsplash
💡
This is part of an on-going series in coding foundations. Check the coding 101 article tag index from time to time for more content.

REST stands for "Representational State Transfer" and is an architectural style (not a protocol or standard) that dictates how a web service API is designed. There are several different facets to it, but the most prominent principles are as follows:

  • Client-Server Architecture
    • REST APIs have a traditional client-server relationship.
    • A "client" (e.g. mobile app, web browser, etc) issues the request. It also typically handles the user interface.
    • A "server" is where the data and logic reside.
  • Statelessness
    • The core idea here is that each request from the client to the server needs to have all the information needed to understand the request.
    • The server doesn't store any client context between requests.
  • Cacheability
    • This means that the responses from the server can be stored (cached) by the client to improve performance and reduce load.
    • Even though responses can be cached, they don't have to. The API server can designate some data as not cacheable so the client doesn't store outdated data.
  • Uniform Interface
    • The system uses a consistent and standardized way to interact with resources.
    • This is typically achieved through standard HTTP methods (e.g. GET, POST, PUT, DELETE, etc)
  • Layered System
    • RESTful APIs support intermediary layers (e.g. proxies or gateways). The client doesn't have to communicate with the end server.
    • This helps improve scalability and security.
  • Code on Demand (Optional)
    • This optional constraint allows servers to extend client functionality by transferring executable code (like JavaScript) to be executed on the client.

This barely scratches the surface of the topic but hopefully it's a good primer. For more information check out the following resources:

What is RESTful API? - RESTful API Explained - AWS
Find out what is RESTful API, how and why businesses use RESTful APIs, and how to use API Gateway with AWS.
What Is a REST API (RESTful API)? | IBM
A REST API is an application programming interface (API) that conforms to design principles of the representational state transfer (REST) architectural style.
What is REST?: REST API Tutorial
REST is an acronym for REpresentational State Transfer. It is an architectural style for hypermedia systems and was first presented by Roy Fielding.