unit 1
unit 1
API Design
UNIT I INTRODUCTION
Web Services - Building Blocks, Types: Service Oriented architectures -
resource oriented architectures, API architectures, Micro services and
architectures, HATEOAS, REST, URI, Code on Demand
TOPIC 1 :Web Services & API
► Web services
► Weather Applications
► Social login
► E-Commerce payments
► Youtube
► API
► Ride booking (Uber,Cal taxi)
► Google Map
Building blocks- Web services
Core components are : 1. SOAP [Link] 3.
WSDL
Building blocks
❖ Uniform Interface: Standardizes interactions by utilizing unique URLs to target data resources and using
uniform actions.
❖ Statelessness: Ensures that every single client request holds all the data needed for processing. The server
❖ Client-Server Separation: Decouples the user interface from the data storage layer so that both components
❖ Cacheable Responses: Forces server communications to label data payload types as cacheable or
❖ Layered System: Enables the application architecture to route traffic across hidden intermediary servers like
► WSDL files are completely language- and platform-independent, making them the cornerstone
of interoperability in Service-Oriented Architectures (SOA). Because it is machine-readable.
► It was started and developed by Microsoft and IBM in March 2001. it is XML based language
format used to describe functionalities and operations involved in web services
Structure of a WSDL document
4. Service Discovery (UDDI)
► UDDI (Universal Description, Discovery, and Integration): A directory service or registry that
allows service providers to advertise their web services and lets requesters locate available
services to use.
► It is an XML-based framework and directory that allows businesses to list, describe, and
discover web services. service providers, access their technical specifications, and integrate
► The two primary types of web services used to exchange data between
applications are
1. RESTful web services and
2. SOAP web services.
► JAX-WS- Java Standard for building SOAP based Web services
► JAX-RS – Java Standard for building RESTful web services
[Link] Web Services
(Representational State Transfer)
► REST is an architectural style rather than a strict protocol.
• Contract: Uses a WSDL (Web Services Description Language) file to explicitly define the
interface and actions available.
• Best For: Enterprise applications, banking systems, and financial transactions requiring high
security
When to use REST (Representational State
Transfer)
► Web and Mobile Applications: Perfect for consuming data in user-facing applications
where bandwidth and payload sizes must be minimal.
► Scalability: The architecture is stateless. Because servers do not have to maintain
session states between requests, they scale much easier.
► Speed and Caching: Supports built-in HTTP caching, which improves performance
and response times for repeated data requests.
► Simplicity and Flexibility: Requires less setup and has a smaller learning curve. It
supports multiple data formats like JSON, XML, and HTML (with JSON being the
most common).
When to use SOAP (Simple Object
Access Protocol)
► Strict Security and Compliance: Built-in WS-Security allows for encrypted, auditable
transactions and digital signatures, making it ideal for financial and healthcare systems.
► Contract-First Requirements: Enforces a rigid contract (WSDL) that guarantees how
client and server must exchange data. This minimizes ambiguity between large
enterprise systems.
► Complex Transactions: Better suited for operations requiring strict ACID compliance
(Atomicity, Consistency, Isolation, Durability) where complete reliability of the
transaction is mandatory.
web services can be categorized into four distinct technical
types based on their underlying architecture and protocols:
RPC web services allow a client to execute a function or procedure on a remote server as if it were running locally.
• XML-RPC: Encodes function calls in basic XML formats and transmits them via HTTP. It is the oldest, most
foundational web service type.
• JSON-RPC: A lightweight alternative that replaces bulky XML formatting with clean JSON scripts.
UDDI serves a specific niche as an information directory rather than a direct communication pipeline.
• Function: It acts like a global "Yellow Pages" directory for businesses to publish, list, and locate available web services
on the internet.
-
SOA
Characteristics
Components
Advantages
High reusability
Easy integration of different applications
Better scalability
Easier maintenance
► Disadvantages
► Complex implementation
► Higher network overhead
► Security challenges
► Can become difficult to manage as the number of services grows
► Applications
► Banking systems (calculating loan ,processing payment)
Applications
SOA is widely used in various industries.
1. Banking Systems
► Online banking
► Fund transfer
► ATM services
► Loan processing
2. E-Commerce
► Online shopping
► Payment gateways
► Order tracking
► Inventory management
3. Healthcare
► Electronic health records
► Appointment scheduling
Continued..
4. Education
► Student information systems
► Online examinations
► Library management
5. Government Services
► Digital identity
► Tax payment
► Passport services
6. Airline Reservation
► Ticket booking
► Flight scheduling
► Online check-in
7. Cloud Computing
Cloud applications use SOA principles to provide scalable and reusable services.
Example of SOA
► It is the structural foundation of RESTful web services, using unique URIs for
identification and standard HTTP methods like GET, POST, PUT, and DELETE to
manipulate them.
► ROA is a paradigm for designing networked software where systems interact via an
Method Purpose
GET Retrieve data
POST Create data
PUT Update data
DELETE Remove data
An ROA system is defined by four core
concepts:
► Resources: These are the informational concepts in a system (e.g., a user profile, an
image, or an order). They can be static or dynamic.
► Representations: Because a client cannot interact directly with server data, a resource
is exposed through a representation, usually formatted as JSON/XML.
► Statelessness: Each HTTP request from a client contains all the information the server
needs to fulfill it, meaning the server does not retain session states between requests.
ROA
Advantages
► Simple architecture
► Lightweight communication
► High scalability
► Easy to develop
Disadvantages
► Less suitable for complex business operations
► Stateless nature may require repeated authentication
Applications
► REST APIs
► Mobile applications
► Cloud services
► Social media APIs
Applications
► 1. E-Commerce Applications
► ROA is used in online shopping websites to manage products, customers, orders, and payments.
► Product catalog
► Shopping cart
► Order management
► Payment processing
► Example: Amazon, Flipkart
Definition
An API (Application Programming Interface) Architecture defines how software
applications communicate using standardized interfaces.
Types of APIs
1. Public APIs
2. Private APIs
3. Partner APIs
4. Composite APIs
Public APIs
► Public APIs (also known as Open APIs or External APIs) are publicly available
to any external developer or business.
► Accessibility: Completely open or requiring minimal registration.
► Security: Often uses public standards like OAuth or basic API keys to track
usage.
► Purpose: Designed to drive innovation, maximize market reach, and expand a
company's software ecosystem.
► Examples: The Google Maps API used to embed maps or the Stripe API used
for open web payments
Private APIs
► Private APIs (also known as Internal APIs) are completely hidden from the
public and are used exclusively within an organization.
► Accessibility: Restricted strictly to internal company developers.
► Security: Governed by strict internal firewalls and proprietary access
credentials.
► Purpose: Built to bridge internal systems, connect data silos, or tie together
company microservices.
► Examples: Connecting a human resources tool to a separate payroll database
Partner APIs
► Partner APIs are shared exclusively with strategic, pre-approved business partners under a
formal agreement.
► Accessibility: Locked to the public but open to verified external B2B collaborators.
► Purpose: Facilitates direct software integration between two cooperative business entities.
► Examples: Amazon connecting its inventory management systems with its certified
third-party shipping carriers.
Composite APIs
► Composite APIs combine multiple individual API endpoints into a single, unified
request and response execution.
► Purpose: Minimizes data traffic, optimizes system speed, and prevents complex
multi-step network lag.
Components
► Client
► API Gateway
► Authentication
► Business Logic
► Database
API Request Flow
Client
↓
API Gateway
↓
Authentication
↓
Application Server
↓
Database
API Styles
► REST API
► Uses HTTP
► JSON data format
► Stateless
► Most commonly used
► SOAP API
► Uses XML
► Strict standards
► High security
► Enterprise applications
► GraphQL API
► Client requests only required data
► Reduces over-fetching
► Flexible queries
• Advantages
► Easy integration
► Faster development
► Reusability
► Better interoperability
► Disadvantages
► Security risks if not protected
► Version management challenges
► Performance depends on network
Applications of API Architecture
► 1. Web Applications
► API architecture is widely used in web applications to connect the frontend with
backend services.
► Examples:
► User authentication
► Product search
► Online forms
► Content management
► 2. Mobile Applications
► Mobile apps use APIs to communicate with servers and retrieve or update data.
► Examples:
► User login
► Profile management
► 3. E-Commerce Platforms
► APIs integrate different services in online shopping systems.
► Examples:
► Product catalog
► Payment gateways
► Order management
► Inventory management
► Shipping and tracking
4. Banking and Financial Services
► Banks use APIs to provide secure online financial services.
► Examples:
► Balance enquiry
► Fund transfer
► Transaction history
► Mobile banking
► 5. Cloud Computing
► Cloud providers offer APIs for managing cloud resources.
► Examples:
► Virtual machine creation
► Cloud storage
► Database management
► User access control
Definition
Microservices Architecture is an architectural style where an application is divided into
small, independent services that communicate through APIs.
Characteristics
► Independent deployment
► Decentralized data management
► Loosely coupled services
► Business capability-based services
► Continuous delivery support
Architecture Diagram
Client
|
API Gateway
/ | \
User Service Product Service Order Service
| | |
User DB Product DB Order DB
Continued..
Features
► Independent services
► Separate databases
► Fault isolation
► Continuous deployment
► Technology independence
Advantages
► High scalability
► Faster deployment
► Easy maintenance
► Better fault tolerance
► Independent development teams
Continued..
Disadvantages
► Complex monitoring
► Network latency
► Distributed transactions
► Increased operational complexity
Applications
► Netflix
► Amazon
► Uber
► Spotify
Example
Example
Applications of Microservices Architecture
► 1. E-Commerce Applications
► Microservices allow different business functions to operate independently.
► Examples:
► User Management Service
► Product Catalog Service
► Shopping Cart Service
► Payment Service
► Order Management Service
► Delivery Tracking Service
► Benefits: Faster development, easy maintenance, and scalability.
► 2. Banking and Financial Systems
► Banks use microservices to separate financial operations into independent services.
► Examples:
► Account Management
► 3. Social Media Platforms
► Large social networking applications use microservices for different features.
► Examples:
► User Profile Service
► News Feed Service
► Messaging Service
► Notification Service
► Photo Upload Service
► Benefits: Individual services can be updated without affecting the entire application.
► 4. Video Streaming Platforms
► Streaming services use microservices to manage various functionalities.
► Examples:
► User Authentication
► Video Catalog
► Video Streaming
► 5. Healthcare Systems
► Hospitals and healthcare organizations use microservices to manage medical information.
► Examples:
► Patient Records
► Appointment Scheduling
► Laboratory Reports
► Pharmacy Management
► Billing
► Benefits: Secure and scalable healthcare applications.
6. Cloud Computing
► Cloud platforms use microservices to deliver cloud services independently.
► Examples:
► Storage Service
► Virtual Machine Management
► Database Service
► 7. Online Booking Systems
► Travel and reservation applications use microservices for different booking operations.
► Examples:
► Flight Booking
► Hotel Reservation
► Railway Booking
► Payment Processing
► Ticket Cancellation
► Benefits: Faster processing and easier integration.
8. Internet of Things (IoT)
► IoT applications use microservices to process data from connected devices.
► Examples:
► Sensor Data Collection
► Device Monitoring
► Alert Management
► 9. Educational Platforms
► Online learning systems use microservices for educational services.
► Examples:
► Student Management
► Course Management
► Online Examination
► Attendance System
► Certificate Generation
► Benefits: Easy feature updates and improved scalability
ROA REST
Architectural style based on resources Architectural principles implementing ROA
Focuses on resources Focuses on resource manipulation
Uses URIs Uses URIs and HTTP methods
Foundation of REST APIs Practical implementation of ROA
Overview
Enterprise
SOA Business services SOAP, REST
applications
Cloud-native and
Small independent REST, gRPC,
Microservices scalable
services Messaging
applications
TOPIC 7 :HATEOAS (Hypermedia As
The Engine Of Application State)
► HATEOAS :It is a core constraint of the REST architectural style. It means that
when a client requests data from a server, the server responds with both the
requested information and dynamic links that guide the client on what actions
to take next.
► It means that a client interacts with a REST API entirely through hyperlinks
(hypermedia) provided dynamically by the server.
► Key Idea
► The server sends data along with links.
► Clients discover available operations by following these links.
► Makes APIs more flexible and self-descriptive.
► Definition
► HATEOAS is a REST principle where the server returns not only the requested
resource but also links to related resources and possible next actions. These
links guide the client through the application.
► How HATEOAS Works
► The client sends a request to the server.
► The server returns the requested resource along with hyperlinks.
► The client follows the hyperlinks to perform the next action.
► The application state changes as the client navigates using the provided links
► Example
► Request:
GET /orders/101
► Response:
In this response:
{
"orderId": 101,
•self → Current order
"status": "Processing", •cancel → Cancel the order
"total": 1500,
•payment → Make payment
"_links": {
"self": {
•customer → View customer details
"href": "/orders/101"
},
The client simply follows these links instead of
"cancel": {
"href": "/orders/101/cancel"
constructing URLs manually.
},
"payment": {
"href": "/orders/101/payment"
},
"customer": {
"href": "/customers/25"
}
Example
► Request
► GET /students/101
Response
{
"id": 101,
"name": "John",
"department": "CSE",
"_links": {
"self": "/students/101",
"update": "/students/101",
"delete": "/students/101",
"courses": "/students/101/courses"
}
}
Advantages
• Easy API navigation
• Loose coupling between client and server
• Better API evolution
• Self-documenting APIs
Disadvantages
• More complex implementation
• Larger response size due to links
• Not supported by every REST API
Applications
• RESTful APIs
• Enterprise applications
• Cloud-based services
TOPIC 8 : REST (Representational
State Transfer)
It is an architectural style for designing web services that uses standard HTTP
methods to access and manipulate resources.
REST Principles
[Link]–Server Architecture
[Link] Communication
[Link] Responses
[Link] Interface
[Link] System
[Link] on Demand (Optional)
HTTP Methods
Method Purpose
GET Retrieve data
POST Create new data
PUT Update existing data
PATCH Partially update data
DELETE Delete data
REST Architecture
Client
|
HTTP Request
|
REST API Server
|
Database
|
HTTP Response (JSON/XML)
Characteristics
• Stateless
• Resource-based
• Lightweight
• Uses HTTP
• Supports JSON and XML
Advantages
• Simple and scalable
• Platform independent
• Fast communication
• Easy integration
Disadvantages
• Stateless communication may require repeated authentication
• Less suitable for very complex transactions
Applications
• Mobile applications
• Web applications
• Cloud computing
• IoT systems
TOPIC 9 : URI (Uniform Resource
Identifier)
Definition
A URI (Uniform Resource Identifier) is a unique identifier used to identify a
resource on the internet.
Types of URI
1. URL (Uniform Resource Locator)
Specifies both the resource and its location.
Example:
[Link]
URN (Uniform Resource Name)
Definition
Code on Demand is an optional REST constraint where the server sends executable code to the
client, allowing the client to extend its functionality dynamically.
How It Works
• The server sends executable code (such as JavaScript).
• The client downloads and executes the code.
• New functionality is added without changing the client application.
Example
A browser requests a webpage.
The server responds with:
• HTML
• CSS
• JavaScript
Architecture
Client
|
Request
|
Server
|
HTML + CSS + JavaScript
|
Client Executes Code
Advantages
• Reduces client updates
• Dynamic functionality
• Better user experience
• Lower server load for some interactions
Disadvantages
• Security concerns
• Increased client complexity
• Browser compatibility issues
Applications
• Web browsers
• Single Page Applications (SPA)
• Interactive websites
• Dynamic web applications
Comparison: REST vs HATEOAS
Discovers endpoints
Client Knowledge Knows endpoints
dynamically
[Link] key must be a string, and the value can be a string, number, array, boolean, or null.
► JSON is often used when data is sent from a server to a web page
► JSON is "self-describing" and easy to understand
► [Link] -- REFERENCE
THANK YOU