What is an API ?

Shivam Jain
5 min readFeb 9, 2024

--

An API, which stands for application programming interface, is a set of protocols that enable different software components to communicate and transfer data.

How do APIs work?

The operation of an API can be succinctly elucidated through a few straightforward steps. Envision a client-server architecture where the client dispatches a request to the server via an intermediary and receives the response through the same intermediary. An API serves as the conduit for communication between two programs or systems. The client represents the user or customer (initiating the request), the intermediary is the API, and the server constitutes the backend (where the request is processed and a response is generated). The sequence of actions in the operation of APIs typically unfolds as follows:

  1. The client triggers the request via the API’s URI (Uniform Resource Identifier).
  2. Upon receiving the request, the API issues a call to the server.
  3. Subsequently, the server forwards the response to the API, along with the requisite information.
  4. Finally, the API relays the data back to the client.

What are the different types of APIs

There exists a multitude of API types, each with distinct categorization methods. One such approach involves classifying APIs based on their accessibility. This organizational framework encompasses the following categories:

  1. Public APIs: These APIs are openly available to developers, typically without restrictions. They are accessible to anyone who wishes to utilize them, often through registration or obtaining an API key.
  2. Private APIs: Contrary to public APIs, private APIs are restricted to specific users or organizations. Access is typically limited to internal systems or partners, requiring authentication and authorization mechanisms for usage.
  3. Partner APIs: Partner APIs are accessible to trusted third-party developers or organizations with whom a partnership or agreement has been established. These APIs enable collaboration and integration between different entities while maintaining controlled access.
  4. Internal APIs: Also known as private APIs, internal APIs are utilized within an organization’s internal systems and are not exposed to external parties. They facilitate communication and data exchange between different components or services within the organization’s infrastructure.
  5. Composite APIs: Composite APIs aggregate functionalities from multiple APIs into a single interface, simplifying complex processes for developers. They enable the orchestration of various API calls to achieve specific tasks or objectives efficiently.
  6. RESTful APIs: Representational State Transfer (REST) APIs adhere to the principles of REST architecture, utilizing standard HTTP methods (GET, POST, PUT, DELETE) for communication. They offer a scalable and stateless approach to web service development, making them widely adopted for building distributed systems.
  7. SOAP APIs: Simple Object Access Protocol (SOAP) APIs employ the XML-based SOAP protocol for exchanging structured information over networks. They provide a standardized and platform-independent method for integrating disparate systems, often used in enterprise environments.

By categorizing APIs according to accessibility, developers can better understand their usage scenarios and select the most suitable APIs for their projects.

What is Postman ?

An API platform for building and using APIs.

Postman simplifies each step of the API lifecycle and streamlines collaboration so you can create better APIs — faster.

Requests and Responses

Request — An API request is a message sent by a client application to an API endpoint, specifying the desired action and data. It includes:

  • Endpoint: URL identifying the resource or action.
  • HTTP Method: Type of action (GET, POST, etc.).
  • Headers: Additional information like authentication.
  • Body (optional): Data sent to the server.
  • Parameters (optional): Extra details for the request.

Respopnse — An API response is a message sent by the API back to the client application after processing a request. It includes:

  • Status Code: Indicating the outcome of the request (e.g., success, error).
  • Headers: Additional information like content type or caching directives.
  • Body (optional): Data returned by the API, such as JSON or XML. The client application receives the response and can then use the returned data or handle any errors accordingly.

HANDS ON PRACTICE ON JOKES API

Here is the link — JOKE API

Scroll till the Try it out here section

You can Select options like what type of jokes you need as per your requirements there are checkboxes, radio buttons and drop down list under which you can select

Here is how you use this api in python

from jokeapi import Jokes # Import the Jokes class
import asyncio

async def print_joke():
j = await Jokes() # Initialise the class
joke = await j.get_joke() # Retrieve a random joke
if joke["type"] == "single": # Print the joke
print(joke["joke"])
else:
print(joke["setup"])
print(joke["delivery"])

asyncio.run(print_joke())

If you want to know how to hit different endpoints you can refer this Guide Python Joke API GUIDE

SOME API TO TRY AS BEGINNER

  1. OpenWeatherMap API: This API provides weather data worldwide. You can retrieve current weather, forecasts, and historical weather data. It’s great for practicing making HTTP requests and handling JSON responses.
  2. Random User Generator API: This API generates random user data like names, addresses, and contact information. It’s useful for practicing working with API requests and parsing JSON responses.
  3. REST Countries API: This API provides information about countries, including basic data such as name, population, area, and more. It’s good for practicing API consumption and data manipulation.
  4. Pokémon TCG API: If you’re interested in gaming, this API provides data about Pokémon Trading Card Game sets, cards, types, and more. It’s a fun way to learn about consuming APIs in the context of a popular franchise.
  5. Chuck Norris Jokes API: This API offers random Chuck Norris jokes. It’s a light-hearted way to practice API consumption and displaying data in your applications.
  6. GitHub API: GitHub offers an API to interact with its repositories, users, and organizations. You can use it to retrieve data about repositories, commits, issues, and more. It’s great for practicing with a real-world API that developers use daily.
  7. NASA API: NASA provides several APIs for accessing space-related data, including images, videos, and astronomy picture of the day. It’s fascinating for anyone interested in space exploration.
  8. The Dog API: This API provides random pictures of dogs, information about breeds, and more. It’s a fun way to practice working with API requests and handling different types of responses.

--

--