SlideShare una empresa de Scribd logo
1 de 79
Descargar para leer sin conexión
Five API Styles
Ronnie Mitra
Director of Design
@mitraman
ronnie.mitra@ca.com
Why API Styles?
▪ Architects of networked/distributed applications have many
decisions to make
▪ Technology changing quickly, new implementations every
year:
– graphQL, gRPC, Kafka, HAL+Forms
▪ Which models of component interaction work best?
The Value of Styles for the Designer
Design a Victorian Style
House
Design a House
Styles, Not Standards
▪ Standards
“Usually a formal document that establishes uniform
engineering or technical criteria, methods, processes and
practices.”
Standards
▪ IETF (HTTP, URI, Basic Auth, etc.)
▪ W3C (SOAP, HTML, RDF, etc.)
▪ OASIS (ebXML, DocBook, WS-Security, etc.)
The Value of Styles for the Designer
▪ Styles describe:
– Characteristics
– Vocabulary
– Constraints
▪ The style is a loose set of rules – the rules become a guide
▪ Styles help designers communicate
Tunnel Style
URI Style
Hypermedia Style
Event Driven Style
Query Style
Style Implementation Considerations
Five properties to consider:
▪ Scalability
▪ Usability
▪ Changeability
▪ Performance
▪ Reliability
Tunnel Style
Tunnel Style: Overview
▪ Application Layer Protocol with a type system and operations
▪ HTTP is not usually required (protocol agnostic)
▪ RPC Interaction
▪ Examples:
– XML-RPC (1998)
– SOAP 1.0 (1999)
– SOAP 1.2 (2003)
– JSON-RPC (2005)
– gRPC (2016)
Tunnel Style: Characteristics
▪ Type and Specification Driven (XML-*, WS-*, Protocol Buffers)
▪ Procedure/Operation based design (“RPC”)
▪ Similar to imperative programming interfaces
Tunnel Style: Primary Constraint
No dependencies on transport layer protocol
Message
HTTP MQ RAW TCP/IP
Client Server
Tunnel Style: Common Implementation Model
Client
Proxy
Service
Proxy
procedure
call
Tooling
Tooling
Interface
Definition
Tunnel Style: Benefits
▪ RPC style is familiar to many developers and architects
▪ Support for heterogeneous networks
▪ Messages can be optimized for point-to-point performance
(reduced size, reduced latency)
Tunnel Style: Limitations
▪ Ignores HTTP features (caching, etc.)
▪ Limited tooling in mobile and web stacks
▪ Change is often costly (highly typed, tightly-coupled)
URI Style
URI Style: Overview
▪ Uses Create, Read, Update, Delete (CRUD) interaction pattern
▪ URI points to a target
▪ Uses HTTP only
URI Style: Characteristics
▪ Use HTTP standard
▪ Object first design
▪ Convention driven
▪ Similar to data object interactions (DAO)
URI Style: Primary Constraint
▪ Interactions must use the CRUD Pattern
CREATE
READ
UPDATE
DELETE
Target Resource
URI Style: Example
▪ GET is used for Retrieval (Read)
▪ http://myapi.com/students points to a collection of student
records
▪ This request means “retrieve a list of student records”
GET http://myapi.com/students
URI Style: Protocol Stack
HTTP (transport)
RFC 7231 et al
URI (for identification)
RFC 3986
MIME (for representation)
XML, JSON, CSV, etc…
URI Style: Common Implementation
Client ServerURIobject
URI Style: Ideal for Data-Centric APIs
DATA-CENTRIC API
Backend
(server)
Frontend
(client)
APPLICATION LOGIC
INPUT HANDLING
LAYOUT IMAGES TEXT
WEATHER DATA
URI Style: Benefits
▪ HTTP path & query is a “well known” – improved usability for
many developers
▪ CRUD pattern is simple and a good fit for “data service”
pattern
▪ Large ecosystem of tools and frameworks today
URI Style: Limitations
▪ CRUD pattern is limited
▪ URI modelling is not standard – every API is a “snowflake”
– Internal domains can benefit from a style guide
– External domains (partner/public) may suffer
▪ Can be “chatty” (esp. when the object passing pattern is used)
▪ API changes usually require client changes, cost is magnified
by scale of client components
Hypermedia Style
Hypermedia Style: Overview
▪ An API with hypermedia features
▪ A browser-like experience for machines
▪ Implemented with links and forms
▪ Example:
– REST (Roy Fielding dissertation)
Hypermedia Style: Characteristics
▪ Focus on transitions
▪ URI is not an object key
▪ Messages are self-documenting
Hypermedia Style: Primary Constraint
▪ Uniform Interface
– Identification of resources
– Manipulation of resources through representations
– Self-descriptive messages
– Hypermedia as the engine of application state
Hypermedia Style: Protocol Stack
Transport Protocol
HTTP, COAP, etc…
Media Type
HTML, ATOM, HAL+JSON, Collection+JSON, etc..
Profiles and Link Relations
hCard, next, prev, etc..
Hypermedia Style: Common Implementation
Client Server
data +
links
templated
input
Hypermedia Style Example: Links
▪ Links tell the client what it can do next
<html>
<body>
<h1>Student Records</h1>
<a href=“/detail?id=3”>Ronnie Mitra</a>
</body>
</html>
Hypermedia Style Example: Links in JSON
{
“name”: “Ronnie”,
“enrollment-year”: “2014”
}
A URI Style JSON Response
Hypermedia Style Example: Links in JSON
{
“name”: “Ronnie”,
“enrollment-year”: “2014”
}
{
“name”: “Ronnie”,
“enrollment-year”: “2014”,
“_address_details”: “/student/ronnie/address”
}
A URI Style JSON Response
A Hypermedia Style JSON Response
Hypermedia Style Example: Generic Data
{
“name”: “Ronnie”,
“enrollment-year”: “2014”,
“_address_details”: “/student/ronnie/address”
}
Hypermedia Style Example: Generic Data
{
“data”: [
{“name”: “student-name”, “value”: “Ronnie”},
{“name”: “enrollment-year”, “value”: “2014”}
],
“_address_details”: “/student/ronnie/address”
}
Hypermedia Style Example: Generic Links
{
“data”: [
{“name”: “student-name”, “value”: “Ronnie”},
{“name”: “enrollment-year”, “value”: “2014”}
],
“_address_details”: “/student/ronnie/address”
}
Hypermedia Style Example: Generic Links
{
“data”: [
{“name”: “student-name”, “value”: “Ronnie”},
{“name”: “enrollment-year”, “value”: “2014”}
],
“_links”: [
{“rel”: “address”, “href”: “/student/ronnie/address”}
]
}
Hypermedia Style: State Machine
▪ Each message represents the current state of the application
▪ Links tell the client what it can do next
▪ The client changes application state by following links
List of Student
Records
You
are
here
Add a new record
See list of schools
Hypermedia Style: Server to Server
Hypermedia ServerMachine Client
LOGIC WEATHER DATA
APPLICATION LOGICSEMANTICS
Hypermedia Style: Mobile Client
INPUT HANDLING
LAYOUT IMAGES TEXT
WEATHER DATA
APPLICATION LOGIC
Hypermedia ServerHuman Facing Client
SEMANTICS
Hypermedia Style: “Browser” Client
INPUT HANDLING
LAYOUT IMAGES TEXT
WEATHER DATA
APPLICATION LOGIC
Hypermedia ServerHuman Facing Client
Hypermedia Style: Benefits
▪ Applications are easier to change (less client code changes
required)
▪ Favours long running and large scale applications
▪ Takes advantage of the WWW architecture
Hypermedia Style: Limitations
▪ Short-term benefits are limited – big up front cost today
▪ Assumed “esoteric”, “too hard”, etc.
▪ Clients are non-trivial to build
▪ Messages are verbose – not optimized for message size
Query Style
Query Style: Overview
▪ Interaction optimized and standardized for querying functions
▪ Learn the location of API and run queries against the data
▪ Suitable for any transport protocol that supports client-server
interactions (usually supports HTTP)
▪ Examples:
– graphQL
– sparQL
– ODBC
– ql.io
Query Style: Characteristics
▪ Treats the API as a data source
▪ A Query Language is defined and standardized (not just
generic support)
▪ Focus is on reading and writing data
Query Style: Primary Constraint
▪ Interactions and data model are constrained by the query
language
Data ModelQuery Language
Query Style Example: GraphQL
POST http://myapi.com/graphql
{
“query”: “
{
student {
name
age
}
}
”
}
Query Style: Protocol Stack
Query Interface Language
X, Y, etc…
Data Model
Relational, CRUD, etc…
Client-Server Transport Protocol
Query Style: Common Implementation
▪ Implement data transformation components on the server to support the
standardized Data Model
▪ Bind a Query Language API to the data transformation
▪ Client implements a client query library
▪ Client uses query client to work with data (in RPC fashion)
Client Server
Data
Transformerqueries Query APIQuery
Client
Query Style: Benefits
▪ All clients and servers that support query standard can
interact easily
▪ Standardizing on language makes tooling possible:
– Data inspection tools
– Frameworks and libraries for clients and servers
▪ Ideal choice for data-centric apps (e.g. mobile apps)
Query Style: Limitations
▪ Features are limited to query language functions
– How do you mutate data?
– What is the performance profile?
– How can you perform non-query operations?
▪ Difficult to use if data model doesn’t match the client’s needs
▪ Changes to data model may require client code changes
Event-Driven Style
Event-Driven Style: Overview
▪ Fire and receive “events”
▪ Asynchronous interactions (one-way)
▪ Sender/Receiver instead of Client/Server
▪ Examples:
– Message Oriented Middleware (e.g. MQ)
– Reactive Programming
– Service Mesh
Event-Driven Style: Protocol Stack
Transport Protocol
HTTP, MQ, TCP/IP, etc…
Event
Custom Design
Event Infrastructure
Event-Driven Style: Constraints and Characteristics
▪ Senders have no knowledge of receivers (e.g. write to queue
or publish to topic)
▪ Event receivers “react” to events
▪ Events represent change to a state
▪ Events can have multiple receivers (subscribers)
EVENT RECEIVER
Event-Driven Style: Primary Constraint
▪ Events occur in the past
▪ You can’t change the past!
TIME
EVENT
Event-Driven Style: Common Implementation
▪ Identify state change events
▪ Register event listener(s)
▪ Sender sends notification when state changes
▪ Event manager transmits notifications
▪ Receiver(s) handle events
Event
Manager
Receiver
Receiver
Sender
Event-Driven Style: Notification Design
▪ Event data may include:
– Target or source of event
– Type of event
– Event details
– Contextual information
{
“event” : {
“name”: “RecordAdded”,
“source”: “StudentRecords”,
“location” : “/students/1883”,
“editing” : “true”
}
}
Event-Driven Style: Internet of Things
▪ Increased use of event driven style in IoT
▪ The real world is based on events
▪ Pervasive technology is primarily event based
LIGHT!
Sensor Event Handler
Event-Driven Style: Microservices
▪ Inter-Service communication (behind firewall)
▪ Cache freshness
▪ Data synchronization / eventual consistency
Data
Changed!
Data Store Lightweight Service
Event-Driven Style: Event Sourcing / Event Store
▪ Persist data state change events
▪ The history of all events is the
“present” state of data
▪ Makes distributed data
architectures easier to implement
Student Created(id=4)
Name Changed(id=4,‘Tin’)
student.id = 4
student.name = Tan
Student.age = 15
student.id = 4
student.name = ‘’
Student.age = ‘’
Age Changed(id=4,15)
Event-Driven Style: Benefits
▪ Components and data can be de-coupled and de-centralized
▪ Ideal for transmitting many changes continuously over time
(e.g. streaming)
▪ De-centralized messaging system offers added reliability
▪ “Reactive” event style offers improved perceived UI
performance
Event-Driven Style: Limitations
▪ Can only record what has already happened (e.g. how do you
perform validation?)
▪ Increases the complexity of the architecture and
infrastructure
▪ Performance, scalability and reliability limited by event
infrastructure
Styles as Metaphors
Style Metaphor
Tunnel Style Procedural programming
URI Style Data Access Objects
Hypermedia Browsing the web
Query Database Query Languages
Event Based Event based programming (e.g. GUI)
A Tunnel Style Example: Microservices Composition
A Tunnel Style Example: Microservices Composition
▪ Publishing new interfaces is cheap and easy for service teams
▪ Service composer team is only client and prepared to rebuild
their component after any service changes (warning:
potential bottleneck)
▪ External component is shielded from change
▪ RPC implementation can be chosen for optimized messaging
speed (e.g. GRPC/Thrift)
URI Style Example: Public Banking API
URI Style Example: Public Banking API
▪ Developers outside the bank will find the URI style familiar
▪ Many of the interactions are well suited for the CRUD pattern
– View transactions
– View balance
– Create payment
▪ Little commercial motivation to make it easy to change API
providers
Hypermedia Style Example: UX Fragmentation
Hypermedia Style Example: UX Fragmentation
▪ Manage and deploy a single client application
▪ Change UI and workflow without re-deploying client
▪ Works best when client development owned by organization
▪ Works best when cheap UX generation is a market
differentiator
Query Style Example: Social Graph Data
Query Style Example: Social Graph Data
▪ Query language optimized for data type
▪ Client development is easier
▪ Backend is optimized for fast reads and complex queries
Event Driven Example: Decentralized Data
Event Driven Example: Decentralized Data
▪ Makes it easier to manage and deploy services independently
▪ Distance between components is small (intranet, not internet)
▪ Data can be “stale”
▪ Libraries/SDK/Sidecars are provided to reduce dev. cost
General Advice for Styles
URI Style
Tunnel Style ▪ Typed interaction, gRPC gaining popularity for
internal use
Hypermedia Style ▪ Most scalable and change-friendly, but least
conventional
▪ The default style for web based APIs
Query Style ▪ Gaining popularity, ideal for internal, data-centric
apps
Event Driven Style ▪ Loose coupled, centralized – good for internal use,
not a good choice for public APIs
Use Your Head
▪ Implementations may borrow from multiple styles
▪ Your system will probably contain more than one API style and
needs will change over time
▪ Start with a style that makes sense for your situation – not
necessarily the one you are “supposed” to use
Five API Styles
Ronnie Mitra
Director of Design
@mitraman
ronnie.mitra@ca.com

Más contenido relacionado

La actualidad más candente

RESTful services
RESTful servicesRESTful services
RESTful services
gouthamrv
 
Building a Distributed Reservation System with Cassandra (Andrew Baker & Jeff...
Building a Distributed Reservation System with Cassandra (Andrew Baker & Jeff...Building a Distributed Reservation System with Cassandra (Andrew Baker & Jeff...
Building a Distributed Reservation System with Cassandra (Andrew Baker & Jeff...
DataStax
 

La actualidad más candente (20)

FIWARE Global Summit - NGSI-LD – an Evolution from NGSIv2
FIWARE Global Summit - NGSI-LD – an Evolution from NGSIv2FIWARE Global Summit - NGSI-LD – an Evolution from NGSIv2
FIWARE Global Summit - NGSI-LD – an Evolution from NGSIv2
 
Session 5 - NGSI-LD Advanced Operations | Train the Trainers Program
Session 5 -  NGSI-LD Advanced Operations | Train the Trainers ProgramSession 5 -  NGSI-LD Advanced Operations | Train the Trainers Program
Session 5 - NGSI-LD Advanced Operations | Train the Trainers Program
 
RDF and OWL
RDF and OWLRDF and OWL
RDF and OWL
 
NoSQL Graph Databases - Why, When and Where
NoSQL Graph Databases - Why, When and WhereNoSQL Graph Databases - Why, When and Where
NoSQL Graph Databases - Why, When and Where
 
Building a Spatial Database in PostgreSQL
Building a Spatial Database in PostgreSQLBuilding a Spatial Database in PostgreSQL
Building a Spatial Database in PostgreSQL
 
Webmapping - Outils OpenSource
Webmapping - Outils OpenSourceWebmapping - Outils OpenSource
Webmapping - Outils OpenSource
 
Session 2 - NGSI-LD primer & Smart Data Models | Train the Trainers Program
Session 2 - NGSI-LD primer & Smart Data Models | Train the Trainers ProgramSession 2 - NGSI-LD primer & Smart Data Models | Train the Trainers Program
Session 2 - NGSI-LD primer & Smart Data Models | Train the Trainers Program
 
PostgreSQL Database Slides
PostgreSQL Database SlidesPostgreSQL Database Slides
PostgreSQL Database Slides
 
FIWARE Training: Introduction to Smart Data Models
FIWARE Training: Introduction to Smart Data ModelsFIWARE Training: Introduction to Smart Data Models
FIWARE Training: Introduction to Smart Data Models
 
What is gRPC introduction gRPC Explained
What is gRPC introduction gRPC ExplainedWhat is gRPC introduction gRPC Explained
What is gRPC introduction gRPC Explained
 
Introduction to gRPC
Introduction to gRPCIntroduction to gRPC
Introduction to gRPC
 
Introduction to SPARQL
Introduction to SPARQLIntroduction to SPARQL
Introduction to SPARQL
 
PostgreSQL
PostgreSQLPostgreSQL
PostgreSQL
 
SHACL by example
SHACL by exampleSHACL by example
SHACL by example
 
RESTful services
RESTful servicesRESTful services
RESTful services
 
Migrating ETL Workflow to Apache Spark at Scale in Pinterest
Migrating ETL Workflow to Apache Spark at Scale in PinterestMigrating ETL Workflow to Apache Spark at Scale in Pinterest
Migrating ETL Workflow to Apache Spark at Scale in Pinterest
 
Introduction to Graph Databases
Introduction to Graph DatabasesIntroduction to Graph Databases
Introduction to Graph Databases
 
Json
JsonJson
Json
 
Knowledge Graphs are Worthless, Knowledge Graph Use Cases are Priceless
Knowledge Graphs are Worthless, Knowledge Graph Use Cases are PricelessKnowledge Graphs are Worthless, Knowledge Graph Use Cases are Priceless
Knowledge Graphs are Worthless, Knowledge Graph Use Cases are Priceless
 
Building a Distributed Reservation System with Cassandra (Andrew Baker & Jeff...
Building a Distributed Reservation System with Cassandra (Andrew Baker & Jeff...Building a Distributed Reservation System with Cassandra (Andrew Baker & Jeff...
Building a Distributed Reservation System with Cassandra (Andrew Baker & Jeff...
 

Similar a Five API Styles

HATEOAS: The Confusing Bit from REST
HATEOAS: The Confusing Bit from RESTHATEOAS: The Confusing Bit from REST
HATEOAS: The Confusing Bit from REST
elliando dias
 
REST API Recommendations
REST API RecommendationsREST API Recommendations
REST API Recommendations
Jeelani Shaik
 
Rest api webinar(3)
Rest api webinar(3)Rest api webinar(3)
Rest api webinar(3)
WSO2
 
REST & API Management with the WSO2 ESB
REST & API Management with the WSO2 ESBREST & API Management with the WSO2 ESB
REST & API Management with the WSO2 ESB
WSO2
 

Similar a Five API Styles (20)

Building Software Backend (Web API)
Building Software Backend (Web API)Building Software Backend (Web API)
Building Software Backend (Web API)
 
Mini-Training: Let's have a rest
Mini-Training: Let's have a restMini-Training: Let's have a rest
Mini-Training: Let's have a rest
 
Linked services
Linked servicesLinked services
Linked services
 
Restful web services with java
Restful web services with javaRestful web services with java
Restful web services with java
 
Hypermedia for Machine APIs
Hypermedia for Machine APIsHypermedia for Machine APIs
Hypermedia for Machine APIs
 
HATEOAS: The Confusing Bit from REST
HATEOAS: The Confusing Bit from RESTHATEOAS: The Confusing Bit from REST
HATEOAS: The Confusing Bit from REST
 
Restful webservice
Restful webserviceRestful webservice
Restful webservice
 
Introduction to the Web API
Introduction to the Web APIIntroduction to the Web API
Introduction to the Web API
 
L19 Application Architecture
L19 Application ArchitectureL19 Application Architecture
L19 Application Architecture
 
SOA1-Background.ppt SOFTWARE ORIENTED SERVICES AND ARCHITECTURE
SOA1-Background.ppt SOFTWARE ORIENTED SERVICES AND ARCHITECTURESOA1-Background.ppt SOFTWARE ORIENTED SERVICES AND ARCHITECTURE
SOA1-Background.ppt SOFTWARE ORIENTED SERVICES AND ARCHITECTURE
 
REST API Recommendations
REST API RecommendationsREST API Recommendations
REST API Recommendations
 
Api design part 1
Api design part 1Api design part 1
Api design part 1
 
Service Oriented Architecture
Service Oriented Architecture Service Oriented Architecture
Service Oriented Architecture
 
Web Standards in FLOSS development
Web Standards in FLOSS developmentWeb Standards in FLOSS development
Web Standards in FLOSS development
 
Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1Code for Startup MVP (Ruby on Rails) Session 1
Code for Startup MVP (Ruby on Rails) Session 1
 
SOA Testing
SOA TestingSOA Testing
SOA Testing
 
Automating the Use of Web APIs through Lightweight Semantics
Automating the Use of Web APIs through Lightweight SemanticsAutomating the Use of Web APIs through Lightweight Semantics
Automating the Use of Web APIs through Lightweight Semantics
 
Rest api webinar(3)
Rest api webinar(3)Rest api webinar(3)
Rest api webinar(3)
 
REST & API Management with the WSO2 ESB
REST & API Management with the WSO2 ESBREST & API Management with the WSO2 ESB
REST & API Management with the WSO2 ESB
 
Overview of java web services
Overview of java web servicesOverview of java web services
Overview of java web services
 

Más de ronniemitra (7)

People Platform Patterns
People Platform PatternsPeople Platform Patterns
People Platform Patterns
 
People Platform Patterns
People Platform PatternsPeople Platform Patterns
People Platform Patterns
 
How We Learn
How We LearnHow We Learn
How We Learn
 
Programming the People Platform
Programming the People PlatformProgramming the People Platform
Programming the People Platform
 
Banking APIs: A Fine Balance
Banking APIs: A Fine BalanceBanking APIs: A Fine Balance
Banking APIs: A Fine Balance
 
Sketching Web APIs
Sketching Web APIsSketching Web APIs
Sketching Web APIs
 
A Simpler Time: A study of complexity in APIs
A Simpler Time: A study of complexity in APIsA Simpler Time: A study of complexity in APIs
A Simpler Time: A study of complexity in APIs
 

Último

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Último (20)

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 

Five API Styles

  • 1. Five API Styles Ronnie Mitra Director of Design @mitraman ronnie.mitra@ca.com
  • 2. Why API Styles? ▪ Architects of networked/distributed applications have many decisions to make ▪ Technology changing quickly, new implementations every year: – graphQL, gRPC, Kafka, HAL+Forms ▪ Which models of component interaction work best?
  • 3. The Value of Styles for the Designer Design a Victorian Style House Design a House
  • 4. Styles, Not Standards ▪ Standards “Usually a formal document that establishes uniform engineering or technical criteria, methods, processes and practices.”
  • 5. Standards ▪ IETF (HTTP, URI, Basic Auth, etc.) ▪ W3C (SOAP, HTML, RDF, etc.) ▪ OASIS (ebXML, DocBook, WS-Security, etc.)
  • 6. The Value of Styles for the Designer ▪ Styles describe: – Characteristics – Vocabulary – Constraints ▪ The style is a loose set of rules – the rules become a guide ▪ Styles help designers communicate
  • 7. Tunnel Style URI Style Hypermedia Style Event Driven Style Query Style
  • 8. Style Implementation Considerations Five properties to consider: ▪ Scalability ▪ Usability ▪ Changeability ▪ Performance ▪ Reliability
  • 10. Tunnel Style: Overview ▪ Application Layer Protocol with a type system and operations ▪ HTTP is not usually required (protocol agnostic) ▪ RPC Interaction ▪ Examples: – XML-RPC (1998) – SOAP 1.0 (1999) – SOAP 1.2 (2003) – JSON-RPC (2005) – gRPC (2016)
  • 11. Tunnel Style: Characteristics ▪ Type and Specification Driven (XML-*, WS-*, Protocol Buffers) ▪ Procedure/Operation based design (“RPC”) ▪ Similar to imperative programming interfaces
  • 12. Tunnel Style: Primary Constraint No dependencies on transport layer protocol Message HTTP MQ RAW TCP/IP
  • 13. Client Server Tunnel Style: Common Implementation Model Client Proxy Service Proxy procedure call Tooling Tooling Interface Definition
  • 14. Tunnel Style: Benefits ▪ RPC style is familiar to many developers and architects ▪ Support for heterogeneous networks ▪ Messages can be optimized for point-to-point performance (reduced size, reduced latency)
  • 15. Tunnel Style: Limitations ▪ Ignores HTTP features (caching, etc.) ▪ Limited tooling in mobile and web stacks ▪ Change is often costly (highly typed, tightly-coupled)
  • 17. URI Style: Overview ▪ Uses Create, Read, Update, Delete (CRUD) interaction pattern ▪ URI points to a target ▪ Uses HTTP only
  • 18. URI Style: Characteristics ▪ Use HTTP standard ▪ Object first design ▪ Convention driven ▪ Similar to data object interactions (DAO)
  • 19. URI Style: Primary Constraint ▪ Interactions must use the CRUD Pattern CREATE READ UPDATE DELETE Target Resource
  • 20. URI Style: Example ▪ GET is used for Retrieval (Read) ▪ http://myapi.com/students points to a collection of student records ▪ This request means “retrieve a list of student records” GET http://myapi.com/students
  • 21. URI Style: Protocol Stack HTTP (transport) RFC 7231 et al URI (for identification) RFC 3986 MIME (for representation) XML, JSON, CSV, etc…
  • 22. URI Style: Common Implementation Client ServerURIobject
  • 23. URI Style: Ideal for Data-Centric APIs DATA-CENTRIC API Backend (server) Frontend (client) APPLICATION LOGIC INPUT HANDLING LAYOUT IMAGES TEXT WEATHER DATA
  • 24. URI Style: Benefits ▪ HTTP path & query is a “well known” – improved usability for many developers ▪ CRUD pattern is simple and a good fit for “data service” pattern ▪ Large ecosystem of tools and frameworks today
  • 25. URI Style: Limitations ▪ CRUD pattern is limited ▪ URI modelling is not standard – every API is a “snowflake” – Internal domains can benefit from a style guide – External domains (partner/public) may suffer ▪ Can be “chatty” (esp. when the object passing pattern is used) ▪ API changes usually require client changes, cost is magnified by scale of client components
  • 27. Hypermedia Style: Overview ▪ An API with hypermedia features ▪ A browser-like experience for machines ▪ Implemented with links and forms ▪ Example: – REST (Roy Fielding dissertation)
  • 28. Hypermedia Style: Characteristics ▪ Focus on transitions ▪ URI is not an object key ▪ Messages are self-documenting
  • 29. Hypermedia Style: Primary Constraint ▪ Uniform Interface – Identification of resources – Manipulation of resources through representations – Self-descriptive messages – Hypermedia as the engine of application state
  • 30. Hypermedia Style: Protocol Stack Transport Protocol HTTP, COAP, etc… Media Type HTML, ATOM, HAL+JSON, Collection+JSON, etc.. Profiles and Link Relations hCard, next, prev, etc..
  • 31. Hypermedia Style: Common Implementation Client Server data + links templated input
  • 32. Hypermedia Style Example: Links ▪ Links tell the client what it can do next <html> <body> <h1>Student Records</h1> <a href=“/detail?id=3”>Ronnie Mitra</a> </body> </html>
  • 33. Hypermedia Style Example: Links in JSON { “name”: “Ronnie”, “enrollment-year”: “2014” } A URI Style JSON Response
  • 34. Hypermedia Style Example: Links in JSON { “name”: “Ronnie”, “enrollment-year”: “2014” } { “name”: “Ronnie”, “enrollment-year”: “2014”, “_address_details”: “/student/ronnie/address” } A URI Style JSON Response A Hypermedia Style JSON Response
  • 35. Hypermedia Style Example: Generic Data { “name”: “Ronnie”, “enrollment-year”: “2014”, “_address_details”: “/student/ronnie/address” }
  • 36. Hypermedia Style Example: Generic Data { “data”: [ {“name”: “student-name”, “value”: “Ronnie”}, {“name”: “enrollment-year”, “value”: “2014”} ], “_address_details”: “/student/ronnie/address” }
  • 37. Hypermedia Style Example: Generic Links { “data”: [ {“name”: “student-name”, “value”: “Ronnie”}, {“name”: “enrollment-year”, “value”: “2014”} ], “_address_details”: “/student/ronnie/address” }
  • 38. Hypermedia Style Example: Generic Links { “data”: [ {“name”: “student-name”, “value”: “Ronnie”}, {“name”: “enrollment-year”, “value”: “2014”} ], “_links”: [ {“rel”: “address”, “href”: “/student/ronnie/address”} ] }
  • 39. Hypermedia Style: State Machine ▪ Each message represents the current state of the application ▪ Links tell the client what it can do next ▪ The client changes application state by following links List of Student Records You are here Add a new record See list of schools
  • 40. Hypermedia Style: Server to Server Hypermedia ServerMachine Client LOGIC WEATHER DATA APPLICATION LOGICSEMANTICS
  • 41. Hypermedia Style: Mobile Client INPUT HANDLING LAYOUT IMAGES TEXT WEATHER DATA APPLICATION LOGIC Hypermedia ServerHuman Facing Client SEMANTICS
  • 42. Hypermedia Style: “Browser” Client INPUT HANDLING LAYOUT IMAGES TEXT WEATHER DATA APPLICATION LOGIC Hypermedia ServerHuman Facing Client
  • 43. Hypermedia Style: Benefits ▪ Applications are easier to change (less client code changes required) ▪ Favours long running and large scale applications ▪ Takes advantage of the WWW architecture
  • 44. Hypermedia Style: Limitations ▪ Short-term benefits are limited – big up front cost today ▪ Assumed “esoteric”, “too hard”, etc. ▪ Clients are non-trivial to build ▪ Messages are verbose – not optimized for message size
  • 46. Query Style: Overview ▪ Interaction optimized and standardized for querying functions ▪ Learn the location of API and run queries against the data ▪ Suitable for any transport protocol that supports client-server interactions (usually supports HTTP) ▪ Examples: – graphQL – sparQL – ODBC – ql.io
  • 47. Query Style: Characteristics ▪ Treats the API as a data source ▪ A Query Language is defined and standardized (not just generic support) ▪ Focus is on reading and writing data
  • 48. Query Style: Primary Constraint ▪ Interactions and data model are constrained by the query language Data ModelQuery Language
  • 49. Query Style Example: GraphQL POST http://myapi.com/graphql { “query”: “ { student { name age } } ” }
  • 50. Query Style: Protocol Stack Query Interface Language X, Y, etc… Data Model Relational, CRUD, etc… Client-Server Transport Protocol
  • 51. Query Style: Common Implementation ▪ Implement data transformation components on the server to support the standardized Data Model ▪ Bind a Query Language API to the data transformation ▪ Client implements a client query library ▪ Client uses query client to work with data (in RPC fashion) Client Server Data Transformerqueries Query APIQuery Client
  • 52. Query Style: Benefits ▪ All clients and servers that support query standard can interact easily ▪ Standardizing on language makes tooling possible: – Data inspection tools – Frameworks and libraries for clients and servers ▪ Ideal choice for data-centric apps (e.g. mobile apps)
  • 53. Query Style: Limitations ▪ Features are limited to query language functions – How do you mutate data? – What is the performance profile? – How can you perform non-query operations? ▪ Difficult to use if data model doesn’t match the client’s needs ▪ Changes to data model may require client code changes
  • 55. Event-Driven Style: Overview ▪ Fire and receive “events” ▪ Asynchronous interactions (one-way) ▪ Sender/Receiver instead of Client/Server ▪ Examples: – Message Oriented Middleware (e.g. MQ) – Reactive Programming – Service Mesh
  • 56. Event-Driven Style: Protocol Stack Transport Protocol HTTP, MQ, TCP/IP, etc… Event Custom Design Event Infrastructure
  • 57. Event-Driven Style: Constraints and Characteristics ▪ Senders have no knowledge of receivers (e.g. write to queue or publish to topic) ▪ Event receivers “react” to events ▪ Events represent change to a state ▪ Events can have multiple receivers (subscribers)
  • 58. EVENT RECEIVER Event-Driven Style: Primary Constraint ▪ Events occur in the past ▪ You can’t change the past! TIME EVENT
  • 59. Event-Driven Style: Common Implementation ▪ Identify state change events ▪ Register event listener(s) ▪ Sender sends notification when state changes ▪ Event manager transmits notifications ▪ Receiver(s) handle events Event Manager Receiver Receiver Sender
  • 60. Event-Driven Style: Notification Design ▪ Event data may include: – Target or source of event – Type of event – Event details – Contextual information { “event” : { “name”: “RecordAdded”, “source”: “StudentRecords”, “location” : “/students/1883”, “editing” : “true” } }
  • 61. Event-Driven Style: Internet of Things ▪ Increased use of event driven style in IoT ▪ The real world is based on events ▪ Pervasive technology is primarily event based LIGHT! Sensor Event Handler
  • 62. Event-Driven Style: Microservices ▪ Inter-Service communication (behind firewall) ▪ Cache freshness ▪ Data synchronization / eventual consistency Data Changed! Data Store Lightweight Service
  • 63. Event-Driven Style: Event Sourcing / Event Store ▪ Persist data state change events ▪ The history of all events is the “present” state of data ▪ Makes distributed data architectures easier to implement Student Created(id=4) Name Changed(id=4,‘Tin’) student.id = 4 student.name = Tan Student.age = 15 student.id = 4 student.name = ‘’ Student.age = ‘’ Age Changed(id=4,15)
  • 64. Event-Driven Style: Benefits ▪ Components and data can be de-coupled and de-centralized ▪ Ideal for transmitting many changes continuously over time (e.g. streaming) ▪ De-centralized messaging system offers added reliability ▪ “Reactive” event style offers improved perceived UI performance
  • 65. Event-Driven Style: Limitations ▪ Can only record what has already happened (e.g. how do you perform validation?) ▪ Increases the complexity of the architecture and infrastructure ▪ Performance, scalability and reliability limited by event infrastructure
  • 66. Styles as Metaphors Style Metaphor Tunnel Style Procedural programming URI Style Data Access Objects Hypermedia Browsing the web Query Database Query Languages Event Based Event based programming (e.g. GUI)
  • 67. A Tunnel Style Example: Microservices Composition
  • 68. A Tunnel Style Example: Microservices Composition ▪ Publishing new interfaces is cheap and easy for service teams ▪ Service composer team is only client and prepared to rebuild their component after any service changes (warning: potential bottleneck) ▪ External component is shielded from change ▪ RPC implementation can be chosen for optimized messaging speed (e.g. GRPC/Thrift)
  • 69. URI Style Example: Public Banking API
  • 70. URI Style Example: Public Banking API ▪ Developers outside the bank will find the URI style familiar ▪ Many of the interactions are well suited for the CRUD pattern – View transactions – View balance – Create payment ▪ Little commercial motivation to make it easy to change API providers
  • 71. Hypermedia Style Example: UX Fragmentation
  • 72. Hypermedia Style Example: UX Fragmentation ▪ Manage and deploy a single client application ▪ Change UI and workflow without re-deploying client ▪ Works best when client development owned by organization ▪ Works best when cheap UX generation is a market differentiator
  • 73. Query Style Example: Social Graph Data
  • 74. Query Style Example: Social Graph Data ▪ Query language optimized for data type ▪ Client development is easier ▪ Backend is optimized for fast reads and complex queries
  • 75. Event Driven Example: Decentralized Data
  • 76. Event Driven Example: Decentralized Data ▪ Makes it easier to manage and deploy services independently ▪ Distance between components is small (intranet, not internet) ▪ Data can be “stale” ▪ Libraries/SDK/Sidecars are provided to reduce dev. cost
  • 77. General Advice for Styles URI Style Tunnel Style ▪ Typed interaction, gRPC gaining popularity for internal use Hypermedia Style ▪ Most scalable and change-friendly, but least conventional ▪ The default style for web based APIs Query Style ▪ Gaining popularity, ideal for internal, data-centric apps Event Driven Style ▪ Loose coupled, centralized – good for internal use, not a good choice for public APIs
  • 78. Use Your Head ▪ Implementations may borrow from multiple styles ▪ Your system will probably contain more than one API style and needs will change over time ▪ Start with a style that makes sense for your situation – not necessarily the one you are “supposed” to use
  • 79. Five API Styles Ronnie Mitra Director of Design @mitraman ronnie.mitra@ca.com