REST API (Representational State Transfer Application Programming Interface) is the backbone of modern web communication. It is the architectural pattern that allows a client (like a mobile app or browser) to talk to a server smoothly and efficiently.
Because it relies on standard HTTP methods, consumes very little bandwidth, and is entirely stateless, it is the number one choice for developers building modern web services.
In this quick guide, we will break down the absolute essentials you need to know about how REST APIs work.
The Client-Server Model
At the heart of any REST API are two separate entities:
- The Client: The application making the request (e.g., your React frontend, a mobile app, or a web browser).
- The Server: The backend system that receives the request, processes the database logic, and returns data in a structured format (usually JSON).
Because they are separated, the client doesn’t need to know how your database works, and the server doesn’t care how the frontend displays the UI. They just pass messages back and forth.
Essential REST HTTP Methods
When a client interacts with a resource via a REST API, it uses standard HTTP methods that map directly to CRUD (Create, Read, Update, Delete) operations.
- GET (Read)
Used to fetch or retrieve data from the server.
- Example Endpoint:
GET /users/1 - What you get back (JSON):
{"id":1,"name":"Dipti","email":"dipti@phpguruacademy.com"}
- POST (Create)
Used to send data to the server to create a brand-new resource.
- Example Endpoint:
POST /users - Request Body sent by client:
{"name":"Dipti","email":"info@phpguruacademy.com"}
- PUT vs. PATCH (Update)
- PUT updates a resource entirely. It completely overwrites the data at that endpoint.
- PATCH updates only a part of the resource (for example, updating -just- a user's email address while leaving their name alone).
- DELETE (Delete)
Completely removes a resource from the server database.
Example Endpoint:
DELETE /users/1👉 Read the full, in-depth article https://phpguruacademy.com/introduction-to-rest-api/!