RESTful API Concepts
A REST API (Representational State Transfer Application Programming Interface) is a software architectural style based on the HTTP protocol, used to build web application interfaces.
The REST API is one of the most commonly used API design patterns in modern web service development.

What is an API?
Basic concepts of an API
An API (Application Programming Interface) is like an "interpreter" between different software. Imagine you go to a foreign restaurant; you don't speak the local language, but the waiter speaks your language, and he is the "interface" between you and the chef.
In the programming world, APIs let different software systems communicate and collaborate. For example:
- Your phone's weather app needs to get weather data
- Your shopping app needs to process payments
- Your social media app needs to upload photos
The role of an API

The main roles of an API include:
- Data exchangeAllows different systems to pass information
- Function reuseAvoid reinventing the wheel; use ready-made services
- System decouplingAllows the front end and back end to be developed independently
- Security controlControls who can access what data
Real-life API analogy
Imagine the API as a restaurant menu:
- The menuis the API documentation, telling you what you can order
- Place an orderis sending a request, telling the waiter what you want
- Serving the dishis receiving the response and getting the food you want
- The waiteris the API, responsible for passing your needs to the kitchen
What is REST?
The meaning of REST
REST (Representational State Transfer) sounds complicated, but it is simply a set of rules and conventions for designing Web APIs. Just as building a house requires following building codes, designing an API also requires following certain standards.
The six principles of REST
1. Client-server architecture
The front end (client) and back end (server) are completely separated, just like customers and the kitchen are separated.

2. Statelessness
Each request is independent, and the server does not remember previous requests. It is like going to the bank each time; you need to show your ID again every time.
3. Cacheability
Response data can be cached to improve performance. It is like a browser caching web page images.
4. Uniform interface
All APIs follow the same rules and format, just like all restaurant menus have a similar structure.
5. Layered system
A system can have multiple layers, for example: client → load balancer → API server → database
6. Code on demand (optional)
The server can send executable code to the client, such as JavaScript.
Why choose REST?
- Simple and easy to understandBased on the HTTP protocol, easy to learn
- LightweightNo extra protocol overhead
- ScalableNew features can be added easily
- Cross-platformAny device that can send an HTTP request can use it