REST API Architectural Constraints
Last Updated :
09 Oct, 2024
REST stands for Representational State Transfer and API stands for Application Program Interface. REST is a software architectural style that defines the set of rules to be used for creating web services. Web services that follow the REST architectural style are known as RESTful web services. It allows requesting systems to access and manipulate web resources by using a uniform and predefined set of rules. Interaction in REST-based systems happens through the Internet’s Hypertext Transfer Protocol (HTTP).
A Restful system consists of a:
- A client who requests for the resources.
- server who has the resources.
It is important to create REST API according to industry standards which results in ease of development and increase client adoption.
Architectural Constraints of RESTful API
There are six architectural constraints that makes any web service are listed below:
- Uniform Interface
- Stateless
- Cacheable
- Client-Server
- Layered System
- Code on Demand
The only optional constraint of REST architecture is code on demand. If a service violates any other constraint, it cannot strictly be referred to as RESTful.
If you’re interested in mastering API design and development, our JavaScript Course covers the fundamentals of REST APIs and demonstrates how to integrate them into JavaScript applications.
Uniform Interface
It is a key constraint that differentiates between a REST API and a Non-REST API. It suggests that there should be a uniform way of interacting with a given server irrespective of device or type of application (website, mobile app).
There are four guidelines principles of a Uniform Interface are:
- Resource-Based: Individual resources are identified in requests. For example: API/users.
- Manipulation of Resources Through Representations: The client has a representation of the resource and it contains enough information to modify or delete the resource on the server, provided it has permission to do so. Example: Usually user gets a user ID when the user requests a list of users and then uses that ID to delete or modify that particular user.
- Self-descriptive Messages: Each message includes enough information to describe how to process the message so that the server can easily analyze the request.
- Hypermedia as the Engine of Application State (HATEOAS): It need to include links for each response so that client can discover other resources easily.
Stateless
It means that the necessary state to handle the request is contained within the request itself and server would not store anything related to the session. In REST, the client must include all information for the server to fulfill the request whether as a part of query params, headers or URI. Statelessness enables greater availability since the server does not have to maintain, update or communicate that session state. There is a drawback when the client need to send too much data to the server so it reduces the scope of network optimization and requires more bandwidth.
Cacheable
Every response should include whether the response is cacheable or not and for how much duration responses can be cached at the client side. Client will return the data from its cache for any subsequent request and there would be no need to send the request again to the server. A well-managed caching partially or completely eliminates some client–server interactions, further improving availability and performance. But sometime there are chances that user may receive stale data.
Client-Server
REST application should have a client-server architecture. A Client is someone who is requesting resources and are not concerned with data storage, which remains internal to each server, and server is someone who holds the resources and are not concerned with the user interface or user state. They can evolve independently. Client doesn’t need to know anything about business logic and server doesn’t need to know anything about frontend UI.
Layered system
An application architecture needs to be composed of multiple layers. Each layer doesn’t know any thing about any layer other than that of immediate layer and there can be lot of intermediate servers between client and the end server. Intermediary servers may improve system availability by enabling load-balancing and by providing shared caches.
Code on demand
It is an optional feature. According to this, servers can also provide executable code to the client. The examples of code on demand may include the compiled components such as Java Servlets and Server-Side Scripts such as JavaScript.
Rules of REST API
There are certain rules which should be kept in mind while creating REST API endpoints.
- REST is based on the resource or noun instead of action or verb based. It means that a URI of a REST API should always end with a noun. Example: /api/users is a good example, but /api?type=users is a bad example of creating a REST API.
- HTTP verbs are used to identify the action. Some of the HTTP verbs are – GET, PUT, POST, DELETE, GET, PATCH.
- A web application should be organized into resources like users and then uses HTTP verbs like – GET, PUT, POST, DELETE to modify those resources. And as a developer it should be clear that what needs to be done just by looking at the endpoint and HTTP method used.
| URI |
HTTP verb |
Description |
| api/users |
GET |
Get all users |
| api/users/new |
GET |
Show form for adding new user |
| api/users |
POST |
Add a user |
| api/users/1 |
PUT |
Update a user with id = 1 |
| api/users/1/edit |
GET |
Show edit form for user with id = 1 |
| api/users/1 |
DELETE |
Delete a user with id = 1 |
| api/users/1 |
GET |
Get a user with id = 1 |
- Always use plurals in URL to keep an API URI consistent throughout the application.
- Send a proper HTTP code to indicate a success or error status.
Note: You can easily use GET and POST but in order to use PUT and DELETE you will need to install method override. You can do this by following below code :
npm install method-override --save
This simply require this package in your code by writing :
var methodOverride = require("method-override");
Now you can easily use PUT and DELETE routes :
app.use(methodOverride("_method"));
HTTP verbs
Some of the common HTTP methods/verbs are described below:
- GET: Retrieves one or more resources identified by the request URI and it can cache the information receive.
- POST: Create a resource from the submission of a request and response is not cacheable in this case. This method is unsafe if no security is applied to the endpoint as it would allow anyone to create a random resource by submission.
- PUT: Update an existing resource on the server specified by the request URI.
- DELETE: Delete an existing resource on the server specified by the request URI. It always return an appropriate HTTP status for every request.
- GET, PUT, DELETE methods are also known as Idempotent methods. Applying an operation once or applying it multiple times has the same effect. Example: Delete any resource from the server and it succeeds with 200 OK and then try again to delete that resource than it will display an error message 410 GONE.
Similar Reads
REST API Architectural Constraints
REST stands for Representational State Transfer and API stands for Application Program Interface. REST is a software architectural style that defines the set of rules to be used for creating web services. Web services that follow the REST architectural style are known as RESTful web services. It all
6 min read
REST API Introduction
REpresentational State Transfer (REST) is an architectural style that defines a set of constraints to be used for creating web services. REST API is a way of accessing web services in a simple and flexible way without having any processing. REST technology is generally preferred to the more robust S
4 min read
REST API in Hyperledger
REST, or Representational State Transfer, is an architectural style for building web services. It is based on a set of principles that define how web resources should be defined, accessed, and manipulated. One of the key principles of REST is the use of the HTTP protocol for communication between cl
7 min read
Comparison between GraphQL & RESTful Architecture
In this article, we will compare RESTful Architecture and GraphQL Architecture. GraphQL is new to the field and RESTful was performing well before the birth of GraphQL. REST: It is an acronym for Representational State Transfer. REST is an API design style architecture to create web services(APIs).
6 min read
Best Coding Practices For Rest API Design
JSON, Endpoints, Postman, CRUD, Curl, HTTP, Status Code, Request, Response, Authentication, All these words are familiar to you if you are in backend development and you have worked on API (Application Programming Interface). Being a developer you might have worked on some kind of APIs (especially t
10 min read
What is API Integration?
An Application Programming Interface or an API is a set of definitions and protocols through which applications communicate with each other. With API your application or service can use the functions provided by another application without needing to know how that other application is being implemen
9 min read
What is an Idempotent REST API?
Idempotent REST API means that if the same request is made a number of times then it will have the same impact as making the request just once. Lastly, the idempotent characteristic is essential for creating dependable and linear web services when clients might attempt to send the same request multi
7 min read
How to Design a Web Application - A Guideline on Software Architecture
Have you ever tried to prepare Pizza at home? (yes!!! we're talking about your favorite food...) What will happen if you don't make good dough for your pizza base? Surely the whole Pizza base will be spoiled and you can't continue with preparing your favorite dish. Whether you're making a pizza or b
11 min read
Latest Web API Technologies
A Web API (Application Programming Interface) is a set of protocols and tools for building software applications. Specifically, a web API is a type of API that is accessed through the internet, typically using HTTP requests. Web APIs allow developers to interact with remote systems or services over
6 min read
Stock Market API Integration in Node.js
In this article, we are going to build a simple web application, in which we would learn how we can integrate a simple API with NodeJS and fetch data from the server using that API. Here, we will learn about what API is, how to get data from the Server using that API and all the stuff related to tha
15+ min read
REST API Call to Get Location Details in Vue.js
In this article, we will know the REST API call to get the location details in VueJS, along with understanding its implementation through the examples. VueJS is one of the best frameworks for JavaScript like ReactJS. The VueJS is used to design the user interface layer, it is easy to pick up for any
7 min read
CRUD Operation in REST API using PHP
A REST (Representational State Transfer) API allows communication between a client and a server through HTTP requests. PHP, a widely used server-side scripting language, is well-suited for creating REST APIs due to its simplicity and rich ecosystem. This article provides a step-by-step guide on buil
5 min read
Richardson Maturity Model - RESTful API
The Richardson Maturity Model (RMM), proposed by Leonard Richardson, is a model used to assess the maturity of a RESTful API based on its implementation levels. It consists of four levels, each representing a stage of maturity in the design and implementation of RESTful principles. Let's delve into
12 min read
How to Create RESTful API and Fetch Data using ReactJS ?
React JS is more than just an open-source JavaScript library, it's a powerful tool for crafting user interfaces with unparalleled efficiency and clarity. One of React's core principles is its component-based architecture, which aligns perfectly with the Model View Controller (MVC) pattern. React com
5 min read
Top 10 API Integration Tools for 2025
n today's business landscape, API integration tools are indispensable for achieving seamless connectivity between diverse applications and services. But why is this so important? APIs (Application Programming Interfaces) facilitate communication between software systems, allowing them to exchange da
13 min read
5 HTTP Methods in RESTful API Development
JavaScript is by far one of the most popular languages when it comes to web development, powering most websites and web applications. Not being limited to only the client-side JavaScript is also one of the most popular languages which are used for developing server-side applications. Organizations u
12 min read
How to connect to an API in JavaScript ?
An API or Application Programming Interface is an intermediary which carries request/response data between the endpoints of a channel. We can visualize an analogy of API to that of a waiter in a restaurant. A typical waiter in a restaurant would welcome you and ask for your order. He/She confirms th
5 min read
Why REST API is Important to Learn?
API... Being a developer what comes to your mind first when you listen to this word... JSON, Endpoints, Postman, CRUD, Curl, HTTP, Status Code, Request, Response, Authentication, or something else... If you're familiar with the above word then surely you might have worked on some kinds of APIs (espe
8 min read
RESTful Statelessness
REST is an acronym for REpresentational State Transfer and an architectural style for distributed hypermedia systems. The six guiding principles or Constraints of REST are: Uniform InterfaceClient-ServerStatelessCacheableLayered architectureCode on demand (optional). We will discuss the Stateless co
2 min read
TypeScript Custom Errors in RESTful API
In this article, we will explore the importance of using custom error handling in TypeScript for RESTful APIs. We will begin by highlighting the problem statement, followed by demonstrating the problem with code examples and error outputs. Finally, we will present a solution approach using custom er
5 min read