DEV Community

Cover image for Day 1: Understanding APIs – The Backbone of Web Communication
Bakare Muideen Adeleke
Bakare Muideen Adeleke

Posted on

Day 1: Understanding APIs – The Backbone of Web Communication

Welcome to Day 1 of my #100DaysOfMiva challenge! Today, we’re diving into the fascinating world of APIs (Application Programming Interfaces). APIs are crucial in the backend development world, enabling different software systems to communicate seamlessly. Let’s break down the key concepts.

What is an API?

An API, or Application Programming Interface, is a set of rules and protocols that allows one software application to interact with another. Think of it as a bridge that connects different systems, allowing them to exchange information and functionality.

How APIs Work

In a typical web application, the communication happens between a client (the web browser) and a server. Here’s a simplified overview:

Client-Server Model: The client sends a request to the server, which processes this request and sends back a response. The client is typically a web browser, mobile app, or any other application that needs data from a server.

Endpoints and Routes: APIs use endpoints (specific URLs) and routes (paths) to handle requests. Each endpoint corresponds to a particular function or resource. For example, a GET /users endpoint might return a list of users, while a POST /users endpoint could create a new user.

Image description

Making API Calls
APIs use HTTP methods to define actions. Here are the most common methods:

GET: Retrieves data from the server. For instance, a request to GET /products would fetch a list of products.

POST: Sends data to the server to create a new resource. For example, POST /orders might be used to place a new order.

PUT: Updates an existing resource. A PUT /users/123 request could update the user with ID 123.

DELETE: Removes a resource. Sending a DELETE /items/456 request would delete the item with ID 456.

Image description

HTTP Status Codes
When the server responds to an API request, it also sends an HTTP status code. These codes indicate the result of the request.

200 OK: The request was successful.

201 Created: The request was successful, and a new resource was created.

400 Bad Request: The request was invalid or cannot be served.

404 Not Found: The requested resource could not be found.

500 Internal Server Error: The server encountered an error.

Image description

Practical Example

Let’s look at a practical example where i will send a GET request to retrieve a list of users:

Request:

https://jsonplaceholder.org/users

Response:

[
{
"id": 1,
"firstname": "John",
"lastname": "Doe",
"email": "johndoe@example.com",
"birthDate": "1973-01-22",
"login": {
"uuid": "1a0eed01-9430-4d68-901f-c0d4c1c3bf22",
"username": "johndoe",
"password": "jsonplaceholder.org",
"md5": "c1328472c5794a25723600f71c1b4586",
"sha1": "35544a31cc19bd6520af116554873167117f4d94",
"registered": "2023-01-10T10:03:20.022Z"
},
"address": {
"street": "123 Main Street",
"suite": "Apt. 4",
"city": "Anytown",
"zipcode": "12345-6789",
"geo": {
"lat": "42.1234",
"lng": "-71.2345"
}
},
"phone": "(555) 555-1234",
"website": "www.johndoe.com",
"company": {
"name": "ABC Company",
"catchPhrase": "Innovative solutions for all your needs",
"bs": "Marketing"
}
},
{
"id": 2,
"firstname": "Jane",
"lastname": "Smith",
"email": "janesmith@example.com",
"birthDate": "1983-02-22",
"login": {
"uuid": "2a0eed02-9430-4d68-901f-c0d4c1c3bf22",
"username": "janesmith",
"password": "jsonplaceholder.org",
"md5": "c1328472c5794a25723600f71c1b4586",
"sha1": "35544a31cc19bd6520af116554873167117f4d94",
"registered": "2022-06-10T12:45:20.022Z"
},
"address": {
"street": "456 Oak Street",
"suite": "Suite 200",
"city": "Anytown",
"zipcode": "12345-6789",
"geo": {
"lat": "42.3456",
"lng": "-71.6789"
}
},
"phone": "(555) 555-5678",
"website": "www.janesmith.com",
"company": {
"name": "XYZ Corporation",
"catchPhrase": "Leading the way in innovation",
"bs": "Finance"
}
}
]

Image description

Day 2, I will be discussing authentication in APIs, which is an essential aspect of securing access and ensuring that only authorized users can interact with the API. Stay tuned!

Top comments (2)

Collapse
 
tobidelly profile image
TD!

Awesome! Bookmarked

Collapse
 
marvellye profile image
Ezekiel Marvellous

Sleek and detailed information about APIs. Well done 👏🏻