What Is API?: Application Programming Interface
What Is API?: Application Programming Interface
1
Introduction to API
API is an interface that allows different
software applications to communicate with
each other.
It defines the rules and methods for this
interaction, enabling data exchange between
systems or applications.
Example:
• A weather app retrieves information from a weather
service by using that service’s API.
2
How APIs Work
APIs work in the following way:
A client sends a request to an API.
Simple Example:
YouTube API: If you want to show a list of trending
videos on your site, you can use YouTube’s API to
fetch and display them.
3
Types of APIs
Open APIs (Public APIs): Available for public
use (e.g., Twitter API).
Partner APIs: Shared with specific business
partners.
Internal APIs (Private APIs): Used within a
company for internal systems.
Composite APIs: Combine multiple APIs to
create complex services.
4
Common API Formats and
Protocols
REST (Representational State Transfer): The most widely
used API architecture for the web, working with JSON or XML
data.
SOAP (Simple Object Access Protocol): An older protocol
that uses XML and ensures higher security.
GraphQL: Allows clients to request specific data in a single
query.
gRPC (gRPC Remote Procedure Call) is an open-source, high-
performance remote procedure call (RPC) framework
developed by Google. It enables communication between
applications by allowing them to call functions or methods
remotely as if they were local. gRPC is known for its
efficiency, making it popular in microservices architectures,
IoT systems, and real-time communication platforms.
5
REST API Example
API: A weather service that provides
temperature data.
Endpoint: GET /weather?
city=London&units=metric
6
REST API Example
7
SOAP API Example
API: A currency exchange service that returns
the exchange rate between two currencies.
Endpoint: POST /CurrencyService
8
SOAP API Example
9
SOAP API Example
10
GraphQL API Example
API: A video service where the user queries for
specific video data.
Endpoint: POST /graphql
11
GraphQL API Example
12
GraphQL API Example
13
gRPC Features
High Performance: Thanks to HTTP/2 and binary
serialization, gRPC ensures low-latency communication,
even for large-scale or time-sensitive applications.
Streaming Support: gRPC enables unary (one-time
request-response) and streaming communication
(where multiple data packets are exchanged over a
single connection).
Multi-language Support: It supports several
programming languages, including Python, Java, C++,
Go, and Node.js.
Strong Typing: Protobuf ensures the structure of the
data exchanged between services is well-defined,
reducing errors.
14
gRPC Example
15
gRPC Example
16
When to Use gRPC?
Microservices: It’s ideal for inter-service
communication due to its high efficiency and low
latency.
IoT Applications: gRPC reduces bandwidth
consumption, making it suitable for constrained
networks.
Real-Time Applications: The streaming capabilities of
HTTP/2 make it suitable for applications requiring
constant data flow, such as chat systems or stock
market feeds.
17
gRPC vs. REST vs.
GraphQL
18
API Usage Statistics (2024)
REST APIs remain the most popular and widely used,
powering around 80% of all web services. Its simplicity,
scalability, and compatibility with most platforms make
it the default choice for many companies.
GraphQL, introduced by Facebook, has seen increased
adoption, used by around 12% of companies. Its
flexibility is highly valued in complex data applications
but requires more setup than REST.
SOAP is used mainly by financial and healthcare sectors
due to its focus on security and transaction
management, accounting for about 5% of the API
landscape.
19
API Usage Statistics (2024)
gRPC (Binary protocol) has grown, especially in
microservices and IoT settings, used by 3% of
companies. Its high performance, enabled through
HTTP/2 and Protocol Buffers, is favored by enterprises
with strict latency requirements.
20
Why Are APIs Important?
Easy Integration: Facilitates smooth
communication between different systems.
Real-Time Data Exchange: APIs allow data
to flow in real-time.
Scalability: Makes it easier to add new
services or features to existing systems.
21
Examples of Popular APIs
YouTube API: Provides access to video data,
including trending videos, playlists, and
comments.
Google Maps API: Enables embedding maps
and location-based services into applications.
OpenWeatherMap API: Delivers weather
data.
22
Custom APIs
A Custom API is built specifically to meet the
unique needs of an organization or project.
While public APIs provide standardized
solutions, custom APIs allow developers to
design specific functionalities tailored to their
requirements.
23
Key Benefits of Custom
APIs:
Tailored Solutions: Offers features specific to
business needs.
Control and Flexibility: Provides full control
over endpoints, data handling, and security
protocols.
Internal Use or Monetization: Can be
designed for internal systems or as a product
for external partners.
24
Custom Binary Protocol
Design and Example
Start Byte:
1 byteValue: 0xAA (Indicates the start of the message)
Length:
2 bytes (Unsigned integer)Specifies the total length of the message, including all fields.
Command Type:
1 byte
Example:0x01: Request for temperature data
Temperature Data:
2 bytes (Unsigned integer)Represents temperature in Celsius × 10. (e.g., 12.1°C is
encoded as 121)
CRC (Cyclic Redundancy Check):
2 bytes (Checksum for error detection)Ensures the message's integrity.
The CRC is a checksum used for error detection.
In our example, it is calculated based on the bytes between the start byte and the CRC
field.
For simplicity, let's assume we use a 16-bit CRC-CCITT algorithm.
25
Custom Binary Protocol
Design and Example
26
Custom Binary Protocol
Design and Example
27
Why Use a Custom Binary
Protocol?
Compact Data Representation: Reduces the size of the
message, which is important for low-bandwidth networks
(like IoT).
Efficient Parsing: Binary data is faster to parse than
text-based formats (e.g., JSON or XML).
Error Detection: With CRC, corrupted messages can be
detected and discarded.
Deterministic Structure: Fixed-length fields allow easy
processing even with limited computing power.
29
Why Use a Binary
Protocol?
Faster Transmission: Binary protocols are
smaller in size and transmit faster over
networks.
Lower Bandwidth Consumption: Ideal for
systems with limited network capacity (e.g.,
IoT devices).
More Secure: Binary data is harder to
interpret, adding a layer of obfuscation.
30
Binary Protocol API
Example
API: A custom API for an IoT system where
sensors send temperature data in binary format.
Protocol: Uses MessagePack for compact binary
data transmission.
32
Binary Protocol API
Example
33
Conclusion
APIs, whether public or custom, are essential
tools in modern software development.
Binary protocols, such as those used in IoT
systems, show how custom APIs can unlock
new efficiencies by optimizing performance.
APIs enable seamless communication
between applications and drive innovation by
connecting different systems effortlessly.
34
API TEST
API testing is a crucial part of the
software development process, ensuring
that APIs function correctly, reliably, and
securely.
35
Define Testing
Requirements: API TEST
Identify Endpoints: Determine which
API endpoints need to be tested (e.g.,
GET, POST, PUT, DELETE).
Understand Specifications: Review
API documentation to understand
expected input and output formats, and
any business rules.
36
Choose a Testing
Methodology: API TEST
37
POSTMAN: API TEST
38
POSTMAN: API TEST
39