Rest by learning REST 🦥
Why Rest is so Popular?
Motivation
“Whenever the work is itself light, it becomes necessary, in order to economize time, to increase the velocity. - Charles Babbage”

Table of Content
- Introduction
- Rest Fundamentals
- SOAP vs REST
- Why and When REST is preffered?
- References
Introduction
As we have already done with API and working of API, now we’re going to learn about REST.
A REST API (Representational State Transfer Application Programming Interface) is a way for different software applications to communicate with each other over the internet using simple commands.
Real-Time Example
Imagine you have a weather app on your phone. When you open the app, it needs to get the latest weather information. Here’s how it might use a REST API:
Request: Your weather app sends a request to a weather server using a URL like https://weatherapi.com/current?city=Hyderabad.
Response: The server processes the request and sends back the current weather data in a format like JSON.
Here’s a simplified example of what the JSON response might look like:
{
"city": "Hyderabad",
"temperature": "32°C",
"condition": "Sunny"
}
AI-generated code. Review and use carefully. More info on FAQ.
How It Works
Client: Your weather app is the client. It makes requests to the server.
Server: The weather server processes the requests and sends back the data.
HTTP Methods: The app uses simple commands like GET (to get data), POST (to send data), PUT (to update data), and DELETE (to delete data).
REST Fundementals
REST is a set of rules for designing networked applications. Here are the six main constraints:
There are 6 rules or constraints like six sigma in REST architecture. We go one by one
- Client-Server : This means that the client (like your web browser) and the server (where the data is stored) are separate. The client requests data, and the server provides it. This separation allows them to evolve independently.
-
Stateless : Each request from the client to the server must contain all the information the server needs to fulfill that request. The server doesn’t store any information about the client between requests. This makes the system more scalable.
-
Cache : Responses from the server can be stored (cached) by the client or an intermediary to improve performance. This means if the same data is requested again, it can be retrieved from the cache instead of the server, saving time.
-
Interface Uniform : This means that the way clients interact with the server is standardized. For example, using standard HTTP methods like GET, POST, PUT, DELETE, and PATCH.
-
Layered system : The architecture can be composed of multiple layers, with each layer only interacting with the layer directly below it. This helps in managing complexity and scalability.
-
Code on Demand : Servers can send executable code to clients when requested. This is optional and not always used.
HTTP methods
We have already learned http status codes we need to know HTTP methods
- POST: Used to create a new resource on the server.
- PUT: Used to update an existing resource or create a new one if it doesn’t exist.
- GET: Used to retrieve data from the server.
- DELETE: Used to delete a resource on the server.
- PATCH: Used to apply partial modifications to a resource.
SOAP vs REST
SOAP (Simple Object Access Protocol) and REST are two different approaches to web services:
SOAP:
- Uses XML for message format.
- More rigid and requires a strict contract between client and server.
- Supports complex operations and has built-in error handling.
- Often used in enterprise environments where security and transactions are critical.
REST:
- Uses standard HTTP methods and can use various formats like JSON, XML, HTML, etc.
- More flexible and easier to use.
- Better suited for web and mobile applications where simplicity and performance are important.
- Easier to scale and integrate with other services.
In summary, REST is like a set of guidelines for building simple, scalable web services, while SOAP is a protocol with more features but also more complexity. REST is often preferred for its simplicity and performance, especially in modern web and mobile applications.
Why and When REST is preffered?
Why REST is Preferred
-
Easy to Use: REST uses simple commands like GET, POST, PUT, DELETE, and PATCH, which are easy to understand and use.
-
Flexible: REST can work with different types of data, like JSON (which is like a text format for data), XML, and more.
-
Scalable: REST doesn’t remember anything about previous requests, so it’s easy to add more servers to handle more users.
-
Fast: REST can save responses so that if the same data is requested again, it can be quickly retrieved without asking the server again.
-
Works Everywhere: REST can be used by any device that can connect to the internet, like web browsers, mobile apps, and other servers.
-
Easy to Maintain: REST uses a standard way for clients to talk to servers, making the code easier to manage and update.
When to Use REST
-
Web and Mobile Apps: REST is great for apps that need to get or send data to a server, like social media apps or online stores.
-
Microservices: REST is good for small services that need to talk to each other over the internet.
-
Public APIs: If you’re making an API for other developers to use, REST is a good choice because it’s simple and widely known.
-
IoT Devices: REST can be used for devices that connect to the internet, like smart home gadgets.
When REST Might Not Be the Best Choice
-
Complex Operations: If your app needs to do complicated tasks that need to be undone if something goes wrong, another method might be better.
-
High Security Needs: While REST can be secure, some other methods have more built-in security features.
-
Old Systems: If you’re working with older systems that already use a different method, it might be easier to stick with that.
In short, REST is popular because it’s simple, flexible, and works well for many modern applications. But for very complex or highly secure tasks, other methods might be better.
References
There are lot of resources and easily available over the internet. I always choose easy and best way of learning . I don’t want to put lot of references and confuse so I’m providing only one referce where you can easily understand about REST in detail restapitutorial .
Happy Learning!!! 🥳🥳
In Next
We are going to learn SpringBoot Basics and then experience the implementation of REST API using SpringBoot.
