Understanding Web API
Understanding Web API
Understanding Web API
Web API
Muhammad Rafaqat
linkedin.com/in/muhammad-rafaqat-ali/ @codewithrafaqat
API
What is an API ?
Example:
When you log in to a website using Google, an API is used
to securely retrieve your account information.
APIs aren’t all the same and come in various forms, each serving
distinct purposes and audiences. Here’s a breakdown of the main
categories of APIs, focusing on access levels, architecture, and
protocols.
Public APIs
Private APIs
Partner APIs
2. Based on Protocols
REST APIs
GraphQL APIs
SOAP
3. Based on Architecture
Monolithic APIs
Microservices APIs
M.Rafaqat
linkedin.com/in/muhammad-rafaqat-ali/
Types of Web APIs
Browser API
Server API
It acts like waitstaff in a restaurant, receive requests for data from client and
relay those requests to the server. Once the server replies, the API channels
that information back to your app.
Third-Party APIs
Instead of building services from scratch for functions like payments or social
media posting, developers can use these APIs for easy access.
1. Monolithic APIs
2. Microservices APIs
1. Public APIs
Also known as open APIs, public APIs are accessible to anyone. They are
designed to be used by third-party developers, allowing for broader
integration and innovation. Examples include social media APIs like Twitter and
Facebook, which enable external applications to interact with their platforms.
2. Private APIs
Private APIs, or internal APIs, are restricted for use within an organization.
They facilitate communication between internal systems and services,
improving efficiency and integration among internal applications.
3. Partner APIs
These APIs are shared with specific partners or clients, allowing controlled
access to certain functionalities or data. They are often used in B2B scenarios
where companies collaborate and share resources.
M.Rafaqat
linkedin.com/in/muhammad-rafaqat-ali/
Based on Protocols
1. REST APIs
Use Case: A blog API that allows clients to fetch, create, or update posts
using standard HTTP requests
2. GraphQL APIs
GraphQL is a query language for APIs that enables clients to request only the
data they need. This flexibility allows for more efficient data retrieval and
reduces over-fetching.
Use Case: A social media platform that allows users to query for specific
data about friends, posts, and interactions.
3. SOAP APIs
Simple Object Access Protocol (SOAP) APIs use XML for message formatting
and are known for their strict standards and protocols. They are often used in
enterprise-level applications requiring high security and reliability.
Use Case: A banking system that needs to ensure secure and structured
data exchange between services.
REST API Example
A simple API for managing books.
Endpoints:
Response
M.Rafaqat
linkedin.com/in/muhammad-rafaqat-ali/
GraphQL Example
The same book management system, but using GraphQL.
Query
Response
Key Differences
REST: You access specific endpoints to retrieve or manipulate resources. Each request is
independent and may return a fixed structure.
GraphQL: You query a single endpoint with a flexible structure, specifying exactly what data
you need. This reduces over-fetching and under-fetching issues.
Fetch API Example
In the below example, we Fetch API to access list of books from a given URL.
The fetch() method returns a promise that we handle using the “then” block.
First, we convert the data into the JSON format. After that, logs the result to
the console.
thank
you