SlideShare une entreprise Scribd logo
1  sur  57
Télécharger pour lire hors ligne
Software Development Done Right
TUTORIAL
Designing a resource model for a Public API
Tom Höfte, IT Architect, Xebia
Marco van der Linden, IT Architect, Xebia
O’Reilly Software Architecture Conference
New York – February 26th , 2018
#OreillySACON
Agenda – 3.5 hours
Introduction &
API Domain
discovery
~ 20 minutes
API Domain
discovery
~ 45 minutes
REST Resource
modeling
~ 20 minutes
REST Resource
modeling
~ 60 minutes
Coffee Break
~ 30 minutes
(3pm)
Other Topics &
Conclusion
~ 20 minutes
(5pm)
Software Development Done Right
Part 0 – Introduction
The API Economy
APIs allow companies to grow and extend businesses at unprecedented rates
by sharing services with third parties – source: Harvard Business Review (https://hbr.org/2015/01/the-strategic-value-of-apis)
{api}
{api}
Note: Slide picture inspired by an idea of Willem van Schieveen, Bol.com
What we, techies, used to think an API is
With the rise of web technologies, the term API is now in general use
and a unique selling point on the web
Component A Component B
API
Remote
CORBA
DCOM
RMI
SOAP WS
Local
A public API is a business service with a web
access point that is managed as a product
We think a public API
• is a open or partner service
• that exposes business capabilities
• through consumer-friendly operations
• that are used to built new applications
• accessible from a web access point
• and follows a product life cycle
API
Private Public
OpenPartner
A typical API architecture: A RESTful API as the
channel to your domain
But why REST?
Business Domain
Model containing data
entities, logic and
operations
Domain model
Message-based
Interface contract
RESTful API Interface
API Consumers
Own devices,
partners or open
An API needs a uniform interface, client-server
decoupling and scalability. REST provides that
{json},
</xml>
Resources,
Representations
and CRUD style operations
HTTP
Caching
URI Format
Request Message
Format
Response
Message Format
HTTP Methods
Scalability
REpresentational State Transfer
using a uniform interface that scales
But…
… how do you create a REST API contract for
your domain?
Domain Model
RESTful API Interface
Describing complex
domain behavior
in a simple REST manner
is not straightforward
Example: Webshop
Customer
Domain REST
Address
Customer
Address
internalId
referenceId
firstname
lastname
addressId
status
groupID
De-normalized in a single REST resource
Create
customer
POST customers
Domain Operations
mapped to
REST operations
{ "customer":{
"referenceId":
"1234"
"firstName": "John"
"lastName": "Doe"
"Address":
{...}
}
}
Representation of
required attributes
in JSON, XML or ..
<customer>
<referenceId>1234</refere
nceId>
<firstName>John<firstName
>
<lastName>Doe</lastName>
<Address>
<...>
</Address>
</customer>
So, resources are the core of a RESTful API…
Resource modeling is therefore a key activity to…
• Map your domain operations to REST operations
• Map your domain data entities to REST resource
representations
…in order create an API that is user-friendly, extensible and
maintainable
Resource Modeling Process
Discover the API
domain
Discover the REST
resources &
operations
Define the API
interface
Software Development Done Right
Part 1 – Discover the API
domain
Goal
Practice how to discover API domain entities, relations and
operations that you need in your API
Discover the API functionality
Inside domain
Outside API domain
Outside API Model ⊂ Inside Business Model
Use a Ubiquitous Language
Protest against any form of:
• Ambiguity
• Inconsistencies
Create bounded context
Bounded context helps:
• To logically group API behavior and
form an API outline
• To structure the later
implementation
Different methods
Input:
- Use case descriptions
- Domain experts, external and internal
Methods:
- Event storming or other work shops
- Text and domain analysis (verbs and nouns)
Output
- A logical domain model depicting
- Set of nouns (entities) and verbs (operations) grouped in
bounded contexts
- Entity relations
Discover your API model
Example: Partial Event–Storming output Webshop
CustomersProduct Shopping Cart Order
Search products
Execute
Payment
Checkout
Shopping Cart
View products in
shopping cart
Add product to
shopping cart Payment
Create Order
Approve
Order
Shopping Ordering Customers
Add
customer
Change
customer
OrderItem
Product
Discover your API model
Example: Partial Webshop domain model
Shopping Ordering
Exercise 1: Discover the API Domain
Exercise Input - Case Description: FlyWithMe airline
FlyWithMe is an airline that wants to increase sales by extending its
current business model towards third parties. They plan to do this by
providing a Public API.
You are an architect at FlyWithMe, responsible for designing the
API.
You and your team decide to start with discovering the domain
entities and operations
…more input is provided in the hand-outs
Exercise outcome
List of domain entities
List of domain operations
Grouped by bounded context
Time left? Try to define the entity relations
Tips
Don’t try to over-complicate the business domain; the goal
is not to get a complete understanding of the domain.
Make assumptions about the business domain where
needed
Focus on API consumer functionality
Do not focus on the attributes of an entity, solely focus on
the nouns and verbs
And now to work!
Organize yourselves in groups of 3-4
Work on exercise till 14:45
Make use of whiteboard, paper, flip overs (easel pad) etc. to
visualize your answer.
Case material: http://bit.ly/restfulapidesign
Retro time
What went well?
What was difficult?
Software Development Done Right
Part 2 – REST resource
modeling
Goal
Learn how to map domain entities and operations to REST
resources and operations
Learn about API documentation options
Practice by modelling basic use cases from the case study
REST API Resource Modeling Process
Discover the API
domain
Discover the REST
resources &
operations
Define the API
interface
From a domain model to a REST contract
A typical flow
Domain
Entities
Domain
operations
Step 2 – Define the API in a
specification language
• Determine the resource
representations
• Operation granularity
Step 1 – Define sequence diagrams
• Group related domain operations in
user stories
• Map domain operations and entities
to REST resources and operations
REST API specification language
Start defining the API using a
API description languages:
- Open API (fka Swagger)
- RAML
- API Blueprint
Kickstart your development
with an API design tool
- SwaggerHub
- Apiary for API blueprint
- Confluence + swagger.io plugin
Anatomy of a RESTful APIREST= Representational State Transfer
Resource Operations = VERBS = GET | POST | PUT | DELETE
Resources representations = NOUNS representations = Media Types (JSON,
XML)
resources = NOUNS
Resource location = URL
REST resource types
• Document: A single document with optional subresources
• https://api.flywithme.com/flightoffers/{id}
• Collection: A server managed collection: a plural noun
• https://api.flywithme.com/airports
REST Operations - Standard HTTP operations
GET https://api.flywithme.com/airports/{airportid}
Retrieve resources
POST https://api.flywithme.com/bookings body: trip
Create a new resource
PUT https://api.flywithme.com/bookings/{bookingid} body: updated trip
Update an existing resource
DELETE https://api.flywithme.com/bookings/{bookingid}
Delete an existing resource
REST Operations – non-CRUD operations
Sometimes it can be difficult to model a business capability
spanning multiple resources with fine-grained HTTP CRUD
operations.
- A business capability is a long-running process
- A business capability is a synchronous function
Add non-CRUD verbs or noun-ified verbs to your API
REST Operations – non-CRUD Verbs
A verb in your URL representing a synchronous action or
function
- Typically modelled with GET
Expedia API: https://developer.ean.com/documentation/rapid-shopping-docs
REST Operations – Noun-ified verbs
A noun representing an
asynchronous action
- Long running
- Action can be monitored
- Typically modelled with
HTTP POST
- REST without PUT /
CQRS
Source: GitHub API
REST Operations – Fine-grained HTTP CRUD
operations or course-grained non-CRUD operations?
It depends:
• CRUD should be your first option
• Use Non-CRUD verbs for synchronous operations for which non-
CRUD becomes clumsy
• Use noun-ified verbs for long running actions or events that must be
monitored
REST Resource Relations
Order
Customer
existentially dependent
non-existentially
dependent
OrderItem
OrderItem
OrderItem
1 N
Order
N
1
REST Resource Relations - Modeling
Resource modeling options:
• Linked Resources
{
orderId: 1
...
customerId: 1
...
}
• Embedded resources
{
id: 1
...
orderItems:
[
{
id: 1
product: "X"
.. }
]
}
Path modeling rules:
• existentially dependent
orders{orderid}orderitems{orderitemid}
• non-existentially dependent
customers{customerid}
REST Resource Representations – Media Types
Mime-types used most often in the Content-Type header:
- application/json
- application/xml
But binary content is also possible:
- Content-Type: application/pdf
Or create your own custom type:
- Content-Type: application/vnd.amazon.ebook
REST operation response codes
Reuse HTTP response code semantics
• Range 2xx – Client message has been received, understood
and processed succesfully
• E.g. Use HTTP 201 when a resource is created
• Range 3xx – Location redirection
• Range 4xx – Request could not be processed due to an error
caused by the client
• Range 5xx – Request could not be processed due to an error
caused by the server
Exercise 2: Discover REST resources
and operations
Exercise input
Take the output of exercise 1 and …
- Take your team result
- Or take our example result
Look at the 2 user stories (*) and define a RESTful API by
- Creating a sequence flow diagram
- A Swagger file specification
(*) User stories will be provided in the exercise
Exercise outcome
For each of the 2 user stories:
Sequence flow diagrams highlighting the REST operations
and resources
An initial swagger file specifying the REST operations and
resources needed to implemented the user stories
And now to work!
Work on the exercise till 16:30
Make use of
- https://www.websequencediagrams.com
- https://editor.swagger.io
- https://swagger.io/specification/
Case material: http://bit.ly/restfulapidesign
Coffee Break
Running out of material, but not out of time ?
You can add the following features:
Notify partner websites with flight updates
Update bookings
Retro time
What went well?
What was difficult?
Software Development Done Right
Part 3 – Other Important
Topics
Hypermedia
• HATEOAS (Hypermedia as the Engine of
Application State) – Richardson Maturity Model
– Level 3
• Self describing, discoverable API
• Changes do not break the contract
• Some frameworks / standardisation efforts:
• Hypertext Application Language – HAL
• Structured Interface for Representing
Entities – SIREN
• JSON-LD and Hydra
• JSON-API
{ "flightOfferSearch": 1
"offset": 0
[
"flightoffer": 1,
"id": 2
"accommodations",
"links": [
{
"href": "1/services",
"rel": "services",
"type" : "GET"
},
{
"href": "1/optionalAccommodations",
"rel": "optionalAccommodations",
"type" : "GET"
}
]
]
"links": [
{
"href": "1/flightoffers/next"
"rel": nextOffset
"type": "GET"
}
]
}
Possible resource
operations defined
in the response
Evolving the API
• By using hypermedia or …
• Support versioning, but only on MAJOR versions
• Make backwards compatible changes and avoid breaking changes
• Deprecate but leave in old functionality
Changes will happen, so design for them.
Webhook pattern
• Event-driven integration via
server callbacks
• Flight updates
• Price changes
• Polling is bad for everyone
• ~95% of polling requests are
useless
• Reduce load on server
Process & People
What have we learned?
Learning points
A RESTful API interface <> your domain model
Embrace non-CRUD operations
Don’t be afraid of changes, but facilitate them in your API
design and in communication to your API consumers
Be pragmatic and work iteratively
Don’t forget about the people and the process
Software Development Done Right
TUTORIAL
Thank you for attending!
Tom Höfte, IT Architect, Xebia, thofte@xebia.com
Marco van der Linden, IT Architect, Xebia, mvanderlinden@xebia.com
#OreillySACON

Contenu connexe

Tendances

DEVOXX UK 2018 - GraphQL as an alternative approach to REST
DEVOXX UK 2018 - GraphQL as an alternative approach to RESTDEVOXX UK 2018 - GraphQL as an alternative approach to REST
DEVOXX UK 2018 - GraphQL as an alternative approach to RESTluisw19
 
How web works and browser works ? (behind the scenes)
How web works and browser works ? (behind the scenes)How web works and browser works ? (behind the scenes)
How web works and browser works ? (behind the scenes)Vibhor Grover
 
Sviluppare App per Office 2013 e SharePoint 2013
Sviluppare App per Office 2013 e SharePoint 2013Sviluppare App per Office 2013 e SharePoint 2013
Sviluppare App per Office 2013 e SharePoint 2013Giuseppe Marchi
 
Understanding and programming the SharePoint REST API
Understanding and programming the SharePoint REST APIUnderstanding and programming the SharePoint REST API
Understanding and programming the SharePoint REST APIChris Beckett
 
SharePoint 2013 REST APIs
SharePoint 2013 REST APIsSharePoint 2013 REST APIs
SharePoint 2013 REST APIsGiuseppe Marchi
 
Developing Apps: Exposing Your Data Through Araport
Developing Apps: Exposing Your Data Through AraportDeveloping Apps: Exposing Your Data Through Araport
Developing Apps: Exposing Your Data Through AraportMatthew Vaughn
 
Introduction to GraphQL: Mobile Week SF
Introduction to GraphQL: Mobile Week SFIntroduction to GraphQL: Mobile Week SF
Introduction to GraphQL: Mobile Week SFAmazon Web Services
 
Designing for SharePoint Provider Hosted Apps
Designing for SharePoint Provider Hosted AppsDesigning for SharePoint Provider Hosted Apps
Designing for SharePoint Provider Hosted AppsRoy Kim
 
SharePoint REST vs CSOM
SharePoint REST vs CSOMSharePoint REST vs CSOM
SharePoint REST vs CSOMMark Rackley
 
GraphQL - A query language to empower your API consumers (NDC Sydney 2017)
GraphQL - A query language to empower your API consumers (NDC Sydney 2017)GraphQL - A query language to empower your API consumers (NDC Sydney 2017)
GraphQL - A query language to empower your API consumers (NDC Sydney 2017)Rob Crowley
 
SharePoint Client Object Model (CSOM)
SharePoint Client Object Model (CSOM)SharePoint Client Object Model (CSOM)
SharePoint Client Object Model (CSOM)Kashif Imran
 
O365Con18 - Create an Immersive Experience with Office365 Data and Mixed Real...
O365Con18 - Create an Immersive Experience with Office365 Data and Mixed Real...O365Con18 - Create an Immersive Experience with Office365 Data and Mixed Real...
O365Con18 - Create an Immersive Experience with Office365 Data and Mixed Real...NCCOMMS
 
SharePoint 2010 Client Object Model
SharePoint 2010 Client Object ModelSharePoint 2010 Client Object Model
SharePoint 2010 Client Object ModelG. Scott Singleton
 

Tendances (17)

DEVOXX UK 2018 - GraphQL as an alternative approach to REST
DEVOXX UK 2018 - GraphQL as an alternative approach to RESTDEVOXX UK 2018 - GraphQL as an alternative approach to REST
DEVOXX UK 2018 - GraphQL as an alternative approach to REST
 
How web works and browser works ? (behind the scenes)
How web works and browser works ? (behind the scenes)How web works and browser works ? (behind the scenes)
How web works and browser works ? (behind the scenes)
 
Sviluppare App per Office 2013 e SharePoint 2013
Sviluppare App per Office 2013 e SharePoint 2013Sviluppare App per Office 2013 e SharePoint 2013
Sviluppare App per Office 2013 e SharePoint 2013
 
Understanding and programming the SharePoint REST API
Understanding and programming the SharePoint REST APIUnderstanding and programming the SharePoint REST API
Understanding and programming the SharePoint REST API
 
SharePoint 2013 REST APIs
SharePoint 2013 REST APIsSharePoint 2013 REST APIs
SharePoint 2013 REST APIs
 
REST API V2
REST API V2REST API V2
REST API V2
 
Rest API
Rest APIRest API
Rest API
 
Developing Apps: Exposing Your Data Through Araport
Developing Apps: Exposing Your Data Through AraportDeveloping Apps: Exposing Your Data Through Araport
Developing Apps: Exposing Your Data Through Araport
 
Introduction to GraphQL: Mobile Week SF
Introduction to GraphQL: Mobile Week SFIntroduction to GraphQL: Mobile Week SF
Introduction to GraphQL: Mobile Week SF
 
The serverless LAMP stack
The serverless LAMP stackThe serverless LAMP stack
The serverless LAMP stack
 
Designing for SharePoint Provider Hosted Apps
Designing for SharePoint Provider Hosted AppsDesigning for SharePoint Provider Hosted Apps
Designing for SharePoint Provider Hosted Apps
 
SharePoint REST vs CSOM
SharePoint REST vs CSOMSharePoint REST vs CSOM
SharePoint REST vs CSOM
 
GraphQL - A query language to empower your API consumers (NDC Sydney 2017)
GraphQL - A query language to empower your API consumers (NDC Sydney 2017)GraphQL - A query language to empower your API consumers (NDC Sydney 2017)
GraphQL - A query language to empower your API consumers (NDC Sydney 2017)
 
SharePoint Client Object Model (CSOM)
SharePoint Client Object Model (CSOM)SharePoint Client Object Model (CSOM)
SharePoint Client Object Model (CSOM)
 
O365Con18 - Create an Immersive Experience with Office365 Data and Mixed Real...
O365Con18 - Create an Immersive Experience with Office365 Data and Mixed Real...O365Con18 - Create an Immersive Experience with Office365 Data and Mixed Real...
O365Con18 - Create an Immersive Experience with Office365 Data and Mixed Real...
 
Ruby on rails
Ruby on railsRuby on rails
Ruby on rails
 
SharePoint 2010 Client Object Model
SharePoint 2010 Client Object ModelSharePoint 2010 Client Object Model
SharePoint 2010 Client Object Model
 

Similaire à O reilly sacon2018nyc - restful api design - master - v1.0

Mind The Gap - Mapping a domain model to a RESTful API - OReilly SACon 2018, ...
Mind The Gap - Mapping a domain model to a RESTful API - OReilly SACon 2018, ...Mind The Gap - Mapping a domain model to a RESTful API - OReilly SACon 2018, ...
Mind The Gap - Mapping a domain model to a RESTful API - OReilly SACon 2018, ...Tom Hofte
 
O'Reilly SACon San Jose, CA - 2019 - API design tutorial
O'Reilly SACon San Jose, CA - 2019 - API design tutorialO'Reilly SACon San Jose, CA - 2019 - API design tutorial
O'Reilly SACon San Jose, CA - 2019 - API design tutorialTom Hofte
 
Getting Started with Office 365 Development
Getting Started with Office 365 DevelopmentGetting Started with Office 365 Development
Getting Started with Office 365 DevelopmentDragan Panjkov
 
Design & Deploy a data-driven Web API in 2 hours
Design & Deploy a data-driven Web API in 2 hoursDesign & Deploy a data-driven Web API in 2 hours
Design & Deploy a data-driven Web API in 2 hoursRestlet
 
Creating a World-Class RESTful Web Services API
Creating a World-Class RESTful Web Services APICreating a World-Class RESTful Web Services API
Creating a World-Class RESTful Web Services APIDavid Keener
 
Xamarin Workshop Noob to Master – Week 5
Xamarin Workshop Noob to Master – Week 5Xamarin Workshop Noob to Master – Week 5
Xamarin Workshop Noob to Master – Week 5Charlin Agramonte
 
APIDays - API Design Workshop
APIDays - API Design WorkshopAPIDays - API Design Workshop
APIDays - API Design WorkshopRestlet
 
Vinay Kumar [InfluxData] | InfluxDB API Overview | InfluxDays 2022
Vinay Kumar [InfluxData] | InfluxDB API Overview  | InfluxDays 2022Vinay Kumar [InfluxData] | InfluxDB API Overview  | InfluxDays 2022
Vinay Kumar [InfluxData] | InfluxDB API Overview | InfluxDays 2022InfluxData
 
Practical guide to building public APIs
Practical guide to building public APIsPractical guide to building public APIs
Practical guide to building public APIsReda Hmeid MBCS
 
REST API Best Practices & Implementing in Codeigniter
REST API Best Practices & Implementing in CodeigniterREST API Best Practices & Implementing in Codeigniter
REST API Best Practices & Implementing in CodeigniterSachin G Kulkarni
 
GraphQL: Enabling a new generation of API developer tools
GraphQL: Enabling a new generation of API developer toolsGraphQL: Enabling a new generation of API developer tools
GraphQL: Enabling a new generation of API developer toolsSashko Stubailo
 
APIs, Web Services, and Mashups: What they are and how they can be used
APIs, Web Services, and Mashups: What they are and how they can be usedAPIs, Web Services, and Mashups: What they are and how they can be used
APIs, Web Services, and Mashups: What they are and how they can be usedsnackeru
 
#ImpactSalesforceSaturday:360 degree view of salesforce integrations
#ImpactSalesforceSaturday:360 degree view of salesforce integrations#ImpactSalesforceSaturday:360 degree view of salesforce integrations
#ImpactSalesforceSaturday:360 degree view of salesforce integrationsNew Delhi Salesforce Developer Group
 
A high profile project with Symfony and API Platform: beIN SPORTS
A high profile project with Symfony and API Platform: beIN SPORTSA high profile project with Symfony and API Platform: beIN SPORTS
A high profile project with Symfony and API Platform: beIN SPORTSSmile I.T is open
 
IBM Integration Bus and REST APIs - Sanjay Nagchowdhury
IBM Integration Bus and REST APIs - Sanjay NagchowdhuryIBM Integration Bus and REST APIs - Sanjay Nagchowdhury
IBM Integration Bus and REST APIs - Sanjay NagchowdhuryKaren Broughton-Mabbitt
 
Building Valuable Restful APIs - HRPHP 2015
Building Valuable Restful APIs - HRPHP 2015Building Valuable Restful APIs - HRPHP 2015
Building Valuable Restful APIs - HRPHP 2015Guillermo A. Fisher
 
INTERFACE, by apidays - Lessons learned from implementing our custom ‘Big Da...
INTERFACE, by apidays  - Lessons learned from implementing our custom ‘Big Da...INTERFACE, by apidays  - Lessons learned from implementing our custom ‘Big Da...
INTERFACE, by apidays - Lessons learned from implementing our custom ‘Big Da...apidays
 
A Snapshot of API Design Trends In 2019
A Snapshot of API Design Trends In 2019A Snapshot of API Design Trends In 2019
A Snapshot of API Design Trends In 2019Bill Doerrfeld
 

Similaire à O reilly sacon2018nyc - restful api design - master - v1.0 (20)

Mind The Gap - Mapping a domain model to a RESTful API - OReilly SACon 2018, ...
Mind The Gap - Mapping a domain model to a RESTful API - OReilly SACon 2018, ...Mind The Gap - Mapping a domain model to a RESTful API - OReilly SACon 2018, ...
Mind The Gap - Mapping a domain model to a RESTful API - OReilly SACon 2018, ...
 
O'Reilly SACon San Jose, CA - 2019 - API design tutorial
O'Reilly SACon San Jose, CA - 2019 - API design tutorialO'Reilly SACon San Jose, CA - 2019 - API design tutorial
O'Reilly SACon San Jose, CA - 2019 - API design tutorial
 
Getting Started with Office 365 Development
Getting Started with Office 365 DevelopmentGetting Started with Office 365 Development
Getting Started with Office 365 Development
 
Design & Deploy a data-driven Web API in 2 hours
Design & Deploy a data-driven Web API in 2 hoursDesign & Deploy a data-driven Web API in 2 hours
Design & Deploy a data-driven Web API in 2 hours
 
Creating a World-Class RESTful Web Services API
Creating a World-Class RESTful Web Services APICreating a World-Class RESTful Web Services API
Creating a World-Class RESTful Web Services API
 
Xamarin Workshop Noob to Master – Week 5
Xamarin Workshop Noob to Master – Week 5Xamarin Workshop Noob to Master – Week 5
Xamarin Workshop Noob to Master – Week 5
 
APIDays - API Design Workshop
APIDays - API Design WorkshopAPIDays - API Design Workshop
APIDays - API Design Workshop
 
Api design part 1
Api design part 1Api design part 1
Api design part 1
 
Vinay Kumar [InfluxData] | InfluxDB API Overview | InfluxDays 2022
Vinay Kumar [InfluxData] | InfluxDB API Overview  | InfluxDays 2022Vinay Kumar [InfluxData] | InfluxDB API Overview  | InfluxDays 2022
Vinay Kumar [InfluxData] | InfluxDB API Overview | InfluxDays 2022
 
Practical guide to building public APIs
Practical guide to building public APIsPractical guide to building public APIs
Practical guide to building public APIs
 
REST API Best Practices & Implementing in Codeigniter
REST API Best Practices & Implementing in CodeigniterREST API Best Practices & Implementing in Codeigniter
REST API Best Practices & Implementing in Codeigniter
 
Databasecentricapisonthecloudusingplsqlandnodejscon3153oow2016 160922021655
Databasecentricapisonthecloudusingplsqlandnodejscon3153oow2016 160922021655Databasecentricapisonthecloudusingplsqlandnodejscon3153oow2016 160922021655
Databasecentricapisonthecloudusingplsqlandnodejscon3153oow2016 160922021655
 
GraphQL: Enabling a new generation of API developer tools
GraphQL: Enabling a new generation of API developer toolsGraphQL: Enabling a new generation of API developer tools
GraphQL: Enabling a new generation of API developer tools
 
APIs, Web Services, and Mashups: What they are and how they can be used
APIs, Web Services, and Mashups: What they are and how they can be usedAPIs, Web Services, and Mashups: What they are and how they can be used
APIs, Web Services, and Mashups: What they are and how they can be used
 
#ImpactSalesforceSaturday:360 degree view of salesforce integrations
#ImpactSalesforceSaturday:360 degree view of salesforce integrations#ImpactSalesforceSaturday:360 degree view of salesforce integrations
#ImpactSalesforceSaturday:360 degree view of salesforce integrations
 
A high profile project with Symfony and API Platform: beIN SPORTS
A high profile project with Symfony and API Platform: beIN SPORTSA high profile project with Symfony and API Platform: beIN SPORTS
A high profile project with Symfony and API Platform: beIN SPORTS
 
IBM Integration Bus and REST APIs - Sanjay Nagchowdhury
IBM Integration Bus and REST APIs - Sanjay NagchowdhuryIBM Integration Bus and REST APIs - Sanjay Nagchowdhury
IBM Integration Bus and REST APIs - Sanjay Nagchowdhury
 
Building Valuable Restful APIs - HRPHP 2015
Building Valuable Restful APIs - HRPHP 2015Building Valuable Restful APIs - HRPHP 2015
Building Valuable Restful APIs - HRPHP 2015
 
INTERFACE, by apidays - Lessons learned from implementing our custom ‘Big Da...
INTERFACE, by apidays  - Lessons learned from implementing our custom ‘Big Da...INTERFACE, by apidays  - Lessons learned from implementing our custom ‘Big Da...
INTERFACE, by apidays - Lessons learned from implementing our custom ‘Big Da...
 
A Snapshot of API Design Trends In 2019
A Snapshot of API Design Trends In 2019A Snapshot of API Design Trends In 2019
A Snapshot of API Design Trends In 2019
 

Dernier

Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Intelisync
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 

Dernier (20)

Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 

O reilly sacon2018nyc - restful api design - master - v1.0

  • 1. Software Development Done Right TUTORIAL Designing a resource model for a Public API Tom Höfte, IT Architect, Xebia Marco van der Linden, IT Architect, Xebia O’Reilly Software Architecture Conference New York – February 26th , 2018 #OreillySACON
  • 2. Agenda – 3.5 hours Introduction & API Domain discovery ~ 20 minutes API Domain discovery ~ 45 minutes REST Resource modeling ~ 20 minutes REST Resource modeling ~ 60 minutes Coffee Break ~ 30 minutes (3pm) Other Topics & Conclusion ~ 20 minutes (5pm)
  • 3. Software Development Done Right Part 0 – Introduction
  • 4. The API Economy APIs allow companies to grow and extend businesses at unprecedented rates by sharing services with third parties – source: Harvard Business Review (https://hbr.org/2015/01/the-strategic-value-of-apis) {api} {api} Note: Slide picture inspired by an idea of Willem van Schieveen, Bol.com
  • 5. What we, techies, used to think an API is With the rise of web technologies, the term API is now in general use and a unique selling point on the web Component A Component B API Remote CORBA DCOM RMI SOAP WS Local
  • 6. A public API is a business service with a web access point that is managed as a product We think a public API • is a open or partner service • that exposes business capabilities • through consumer-friendly operations • that are used to built new applications • accessible from a web access point • and follows a product life cycle API Private Public OpenPartner
  • 7. A typical API architecture: A RESTful API as the channel to your domain But why REST? Business Domain Model containing data entities, logic and operations Domain model Message-based Interface contract RESTful API Interface API Consumers Own devices, partners or open
  • 8. An API needs a uniform interface, client-server decoupling and scalability. REST provides that {json}, </xml> Resources, Representations and CRUD style operations HTTP Caching URI Format Request Message Format Response Message Format HTTP Methods Scalability REpresentational State Transfer using a uniform interface that scales But…
  • 9. … how do you create a REST API contract for your domain? Domain Model RESTful API Interface Describing complex domain behavior in a simple REST manner is not straightforward
  • 10. Example: Webshop Customer Domain REST Address Customer Address internalId referenceId firstname lastname addressId status groupID De-normalized in a single REST resource Create customer POST customers Domain Operations mapped to REST operations { "customer":{ "referenceId": "1234" "firstName": "John" "lastName": "Doe" "Address": {...} } } Representation of required attributes in JSON, XML or .. <customer> <referenceId>1234</refere nceId> <firstName>John<firstName > <lastName>Doe</lastName> <Address> <...> </Address> </customer>
  • 11. So, resources are the core of a RESTful API… Resource modeling is therefore a key activity to… • Map your domain operations to REST operations • Map your domain data entities to REST resource representations …in order create an API that is user-friendly, extensible and maintainable
  • 12. Resource Modeling Process Discover the API domain Discover the REST resources & operations Define the API interface
  • 13. Software Development Done Right Part 1 – Discover the API domain
  • 14. Goal Practice how to discover API domain entities, relations and operations that you need in your API
  • 15. Discover the API functionality Inside domain Outside API domain Outside API Model ⊂ Inside Business Model
  • 16. Use a Ubiquitous Language Protest against any form of: • Ambiguity • Inconsistencies
  • 17. Create bounded context Bounded context helps: • To logically group API behavior and form an API outline • To structure the later implementation
  • 18. Different methods Input: - Use case descriptions - Domain experts, external and internal Methods: - Event storming or other work shops - Text and domain analysis (verbs and nouns) Output - A logical domain model depicting - Set of nouns (entities) and verbs (operations) grouped in bounded contexts - Entity relations
  • 19. Discover your API model Example: Partial Event–Storming output Webshop CustomersProduct Shopping Cart Order Search products Execute Payment Checkout Shopping Cart View products in shopping cart Add product to shopping cart Payment Create Order Approve Order Shopping Ordering Customers Add customer Change customer OrderItem Product
  • 20. Discover your API model Example: Partial Webshop domain model Shopping Ordering
  • 21. Exercise 1: Discover the API Domain
  • 22. Exercise Input - Case Description: FlyWithMe airline FlyWithMe is an airline that wants to increase sales by extending its current business model towards third parties. They plan to do this by providing a Public API. You are an architect at FlyWithMe, responsible for designing the API. You and your team decide to start with discovering the domain entities and operations …more input is provided in the hand-outs
  • 23. Exercise outcome List of domain entities List of domain operations Grouped by bounded context Time left? Try to define the entity relations
  • 24. Tips Don’t try to over-complicate the business domain; the goal is not to get a complete understanding of the domain. Make assumptions about the business domain where needed Focus on API consumer functionality Do not focus on the attributes of an entity, solely focus on the nouns and verbs
  • 25. And now to work! Organize yourselves in groups of 3-4 Work on exercise till 14:45 Make use of whiteboard, paper, flip overs (easel pad) etc. to visualize your answer. Case material: http://bit.ly/restfulapidesign
  • 26. Retro time What went well? What was difficult?
  • 27. Software Development Done Right Part 2 – REST resource modeling
  • 28. Goal Learn how to map domain entities and operations to REST resources and operations Learn about API documentation options Practice by modelling basic use cases from the case study
  • 29. REST API Resource Modeling Process Discover the API domain Discover the REST resources & operations Define the API interface
  • 30. From a domain model to a REST contract A typical flow Domain Entities Domain operations Step 2 – Define the API in a specification language • Determine the resource representations • Operation granularity Step 1 – Define sequence diagrams • Group related domain operations in user stories • Map domain operations and entities to REST resources and operations
  • 31. REST API specification language Start defining the API using a API description languages: - Open API (fka Swagger) - RAML - API Blueprint Kickstart your development with an API design tool - SwaggerHub - Apiary for API blueprint - Confluence + swagger.io plugin
  • 32. Anatomy of a RESTful APIREST= Representational State Transfer Resource Operations = VERBS = GET | POST | PUT | DELETE Resources representations = NOUNS representations = Media Types (JSON, XML) resources = NOUNS Resource location = URL
  • 33. REST resource types • Document: A single document with optional subresources • https://api.flywithme.com/flightoffers/{id} • Collection: A server managed collection: a plural noun • https://api.flywithme.com/airports
  • 34. REST Operations - Standard HTTP operations GET https://api.flywithme.com/airports/{airportid} Retrieve resources POST https://api.flywithme.com/bookings body: trip Create a new resource PUT https://api.flywithme.com/bookings/{bookingid} body: updated trip Update an existing resource DELETE https://api.flywithme.com/bookings/{bookingid} Delete an existing resource
  • 35. REST Operations – non-CRUD operations Sometimes it can be difficult to model a business capability spanning multiple resources with fine-grained HTTP CRUD operations. - A business capability is a long-running process - A business capability is a synchronous function Add non-CRUD verbs or noun-ified verbs to your API
  • 36. REST Operations – non-CRUD Verbs A verb in your URL representing a synchronous action or function - Typically modelled with GET Expedia API: https://developer.ean.com/documentation/rapid-shopping-docs
  • 37. REST Operations – Noun-ified verbs A noun representing an asynchronous action - Long running - Action can be monitored - Typically modelled with HTTP POST - REST without PUT / CQRS Source: GitHub API
  • 38. REST Operations – Fine-grained HTTP CRUD operations or course-grained non-CRUD operations? It depends: • CRUD should be your first option • Use Non-CRUD verbs for synchronous operations for which non- CRUD becomes clumsy • Use noun-ified verbs for long running actions or events that must be monitored
  • 39. REST Resource Relations Order Customer existentially dependent non-existentially dependent OrderItem OrderItem OrderItem 1 N Order N 1
  • 40. REST Resource Relations - Modeling Resource modeling options: • Linked Resources { orderId: 1 ... customerId: 1 ... } • Embedded resources { id: 1 ... orderItems: [ { id: 1 product: "X" .. } ] } Path modeling rules: • existentially dependent orders{orderid}orderitems{orderitemid} • non-existentially dependent customers{customerid}
  • 41. REST Resource Representations – Media Types Mime-types used most often in the Content-Type header: - application/json - application/xml But binary content is also possible: - Content-Type: application/pdf Or create your own custom type: - Content-Type: application/vnd.amazon.ebook
  • 42. REST operation response codes Reuse HTTP response code semantics • Range 2xx – Client message has been received, understood and processed succesfully • E.g. Use HTTP 201 when a resource is created • Range 3xx – Location redirection • Range 4xx – Request could not be processed due to an error caused by the client • Range 5xx – Request could not be processed due to an error caused by the server
  • 43. Exercise 2: Discover REST resources and operations
  • 44. Exercise input Take the output of exercise 1 and … - Take your team result - Or take our example result Look at the 2 user stories (*) and define a RESTful API by - Creating a sequence flow diagram - A Swagger file specification (*) User stories will be provided in the exercise
  • 45. Exercise outcome For each of the 2 user stories: Sequence flow diagrams highlighting the REST operations and resources An initial swagger file specifying the REST operations and resources needed to implemented the user stories
  • 46. And now to work! Work on the exercise till 16:30 Make use of - https://www.websequencediagrams.com - https://editor.swagger.io - https://swagger.io/specification/ Case material: http://bit.ly/restfulapidesign
  • 48. Running out of material, but not out of time ? You can add the following features: Notify partner websites with flight updates Update bookings
  • 49. Retro time What went well? What was difficult?
  • 50. Software Development Done Right Part 3 – Other Important Topics
  • 51. Hypermedia • HATEOAS (Hypermedia as the Engine of Application State) – Richardson Maturity Model – Level 3 • Self describing, discoverable API • Changes do not break the contract • Some frameworks / standardisation efforts: • Hypertext Application Language – HAL • Structured Interface for Representing Entities – SIREN • JSON-LD and Hydra • JSON-API { "flightOfferSearch": 1 "offset": 0 [ "flightoffer": 1, "id": 2 "accommodations", "links": [ { "href": "1/services", "rel": "services", "type" : "GET" }, { "href": "1/optionalAccommodations", "rel": "optionalAccommodations", "type" : "GET" } ] ] "links": [ { "href": "1/flightoffers/next" "rel": nextOffset "type": "GET" } ] } Possible resource operations defined in the response
  • 52. Evolving the API • By using hypermedia or … • Support versioning, but only on MAJOR versions • Make backwards compatible changes and avoid breaking changes • Deprecate but leave in old functionality Changes will happen, so design for them.
  • 53. Webhook pattern • Event-driven integration via server callbacks • Flight updates • Price changes • Polling is bad for everyone • ~95% of polling requests are useless • Reduce load on server
  • 55. What have we learned?
  • 56. Learning points A RESTful API interface <> your domain model Embrace non-CRUD operations Don’t be afraid of changes, but facilitate them in your API design and in communication to your API consumers Be pragmatic and work iteratively Don’t forget about the people and the process
  • 57. Software Development Done Right TUTORIAL Thank you for attending! Tom Höfte, IT Architect, Xebia, thofte@xebia.com Marco van der Linden, IT Architect, Xebia, mvanderlinden@xebia.com #OreillySACON