APIs & RESTful API

Introduction:

AKRAM BOUTZOUGA
5 min readMay 29, 2024

Technically, An API or Application Programming Interface, is a set of rules and tools that allows different software applications to communicate with each other. Think of it as a translator that helps two programs understand each other, even if they are built differently.

Here’s a simple analogy: Imagine you’re at a restaurant. You (the customer) don’t go into the kitchen to prepare your meal. Instead, you place an order with the waiter (the API). The waiter takes your order to the kitchen (the server), where the chefs (the backend services) prepare your meal. The waiter then brings your food back to you. You don’t need to know how the kitchen operates or how the food is prepared; you just need the waiter to bring you what you asked for. Similarly, with an API, you don’t need to know the internal workings of the other software. You just use the API to request data or services, and it takes care of the rest.

APIs are widely used in various applications, from web services to mobile apps, allowing them to work together seamlessly. For example, when you use an app to check the weather, it likely uses an API to get the latest weather data from another service.

What are Different Types of APIs?

There are many different types of APIs for operating systems, applications or websites.

What are Examples of Popular APIs?

The following list contains several examples of popular APIs:

Examples of Popular APIs:

  1. Google Maps API: The Google Maps API lets developers embed Google Maps on webpages using a JavaScript or Flash interface. The Google Maps API is designed to work on mobile devices and desktop browsers.
  2. YouTube APIs: YouTube’s APIs let developers integrate YouTube videos and functionality into websites or applications. YouTube APIs include the YouTube Analytics API, YouTube Data API, YouTube Live Streaming API, YouTube Player APIs, and others.
  3. Flickr API: The Flickr API is used by developers to access the Flick photo sharing community data. The Flickr API consists of a set of callable methods, and some API endpoints.
  4. Twitter APIs: Twitter offers two APIs. The REST API allows developers to access core Twitter data and the Search API provides methods for developers to interact with Twitter search and trends data.
  5. Amazon Product Advertising API: Amazon’s Product Advertising API gives developers access to Amazon’s product selection and discovery functionality. Devs can then incorporate advertisements of Amazon products to monetize a website.

Rest or Restful Api:

An API(Application Programming Interface) allows two computers to communicate by sending requests and receiving responses. RESTful APIs follow specific rules for organizing data and using HTTP methods like GET, POST, PATCH, and DELETE.

REST(REpresentational State Transfer) API is a software architectural style for Backend, to debunk this:

Architectural Style

REST is not a protocol or standard; it’s an architectural style that defines a set of constraints and properties based on HTTP.

Resources

In REST, everything is considered a resource, identified by a URL (Uniform Resource Locator). Resources can be anything from data objects to services. An object is “displayed” or transferred via a representation (typically JSON). HTTP methods define the actions on a resource.

Backend

A REST API is implemented on the backend to expose data and functionality to clients.

Rest Api Architecture

Example:

Book Management System:

Resources:

  • Books: Each book has properties like id, title, author, and published_date.

HTTP Methods and Endpoints:

  • GET /books: Read representation of a resource or a list of resources

Request:

GET /books HTTP/1.1
Host: api.example.com

Response:

[
{
"id": 1,
"title": "1984",
"author": "George Orwell",
"published_date": "1949-06-08"
},
{
"id": 2,
"title": "To Kill a Mockingbird",
"author": "Harper Lee",
"published_date": "1960-07-11"
}
]
  • GET /books/{id}:

Request:

GET /books/1 HTTP/1.1
Host: api.example.com

Response:

{
"id": 1,
"title": "1984",
"author": "George Orwell",
"published_date": "1949-06-08"
}
  • POST /books: Create a new resource

Request:

POST /books HTTP/1.1
Host: api.example.com
Content-Type: application/json

{
"title": "Brave New World",
"author": "Aldous Huxley",
"published_date": "1932-08-01"
}

Response:

HTTP/1.1 201 Created
Location: /books/3
  • PUT /books/{id}:

Request:

PUT /books/1 HTTP/1.1
Host: api.example.com
Content-Type: application/json

{
"title": "1984",
"author": "George Orwell",
"published_date": "1949-06-08"
}

Response:

HTTP/1.1 200 OK
  • DELETE /books/{id}: Remove an existing resource

Request:

DELETE /books/1 HTTP/1.1
Host: api.example.com

Response:

HTTP/1.1 204 No Content
  • PATCH /books/{id}: Partially update an existing resource

Request:

PATCH /books/1 HTTP/1.1
Host: api.example.com
Content-Type: application/json

{
"published_date": "1950-06-08"
}

Response:

HTTP/1.1 200 OK

Difference Between General Api and Rest Api:

+-----------------------------------+
| REST API |
|-----------------------------------|
| Protocol: HTTP/HTTPS |
|-----------------------------------|
| Data Formats: |
| - JSON |
| - XML |
|-----------------------------------|
| HTTP Methods: |
| - GET |
| - POST |
| - PUT |
| - PATCH |
| - DELETE |
|-----------------------------------|
| Principles: |
| - Stateless |
| - Resource-Oriented |
| - Uniform Interface |
| - Cacheable |
| - Client-Server Architecture |
+-----------------------------------+


+-----------------------------------+
| General API |
|-----------------------------------|
| Protocols: |
| - HTTP |
| - HTTPS |
| - SOAP |
| - XML-RPC |
|-----------------------------------|
| Data Formats: |
| - JSON |
| - XML |
| - Plain Text |
|-----------------------------------|
| Functions and Methods: |
| - Various Function Calls |
| - Diverse Operations |
+-----------------------------------+

In summary, while an API is a broad term for any interface that allows software to communicate, a REST API is a specific type of API that follows the principles of REST and uses HTTP for communication.

and Because I’m no expert on this topic, consider this article as my public note on the topic where I synthesized the best resources to help you understand, I recommend you check the resources below:

Interesting Resources you should check:

Free Apis to test your skills:

--

--

AKRAM BOUTZOUGA
AKRAM BOUTZOUGA

Written by AKRAM BOUTZOUGA

Junior Calisthenics Engineer, Ai Enthusiast. Coding and Flexing! 💻💪

No responses yet