What is an API ?
<aside>
💬
Think of an API like a waiter in a restaurant.
- You (The User/Client): You are sitting at the table with a menu. You cannot go into the kitchen and cook the food yourself.
- The Kitchen (The Server/System): This is where the food (data/service) is prepared.
- The Waiter (The API): You tell the waiter what you want. The waiter takes your order to the kitchen, the kitchen prepares it, and the waiter brings the food back to
</aside>
Request Type :
<aside>
💬
1. URL (Uniform Resource Locator)
This is the address of the resource you are trying to reach.
- Example:
https://jsonplaceholder.typicode.com/todos/1
- It tells the internet exactly where the server is located and which specific data you want.
2. Method (Type)
The "Type" defines what action you want the server to take. The most common methods are:
- GET: Retrieve data from the server (like loading a profile page).
- POST: Send new data to the server (like submitting a registration form).
- PUT / PATCH: Update existing data on the server.
- DELETE: Remove data from the server.
3. Parameters (Params)
These are used to provide specific details or filters for the request. They are divided into three types:
- Path Parameters: Part of the URL path used to identify a specific resource (e.g., the
100 in /posts/100).
- Query Params: Added to the end of a URL after a
? to filter or sort data (e.g., /posts?userId=1).
- Body Params: Data sent inside the "body" of the request. This is usually used with POST or PUT requests to send complex data like JSON objects (e.g., a username and password).
4. Headers
Headers contain "metadata" or extra information about the request. They don't contain the primary data but provide context, such as:
- Content-Type: Tells the server if you are sending JSON, HTML, or an image.
- Authorization: Contains tokens or keys to prove you have permission to access the data.
- User-Agent: Identifies which browser or device is making the request.
How it works in a cycle:
- Request: You (the Client) send a request with a URL, Method, Headers, and sometimes a Body.
- Processing: The Server receives the request, identifies what you need, and processes it.
- Response: The Server sends back a Response, which usually includes a status code (like
200 OK or 404 Not Found) and the data you asked for.
</aside>
Write Here …
<aside>
💬
</aside>