SlideShare a Scribd company logo
Hypermedia API
and
how to document it
effectively
Sanjoy Roy
What is hypertext and
hypermedia?
Hypertext is text
which contains links to
other text.
The ter m “ hyper text” w as
c oined by
Ted N els on ar ound 1965
Hypermedia is an
extension
of the term
hypertext.
It can include
graphics, audio,
video, sound, plain
text, and links.
Hypermedia
as the engine
of application
state
(HATEOAS) Roy Fielding
6 3 1
4
3
5
1
5
Application
starts by
transitioning to
the state
identified by
URI (6)
State
representation
contains links
to states (4),
(3), and (5)
Application
chooses to
transition to the
state identified by
URI (3)
State
representation
contains links
to states (1)
and (5)
Application
chooses to
transition to the
state identified by
URI (1)
Active state does
not contain any
link for making
forward progress
REST – five key principles
Thinking in
Resource
and give it
an id
Resource has
multiple
representations
Use standard
HTTP methods
Stateless
Communication
Link
resources
together
Hypermedia API
 Uses a set of functions that
accept parameters and
return objects and/or
collections
 Just Data
 State transitions are
documented as static URLs
 In most cases it documents
a single instance – a
solution for a problem
domain
RPC-style API
 Mirrors the way web interactions
were originally designed via links
and forms
 Uses registered media types like
HTML, Atom, HAL, Siren,
Collection-json
 Data + hypermedia controls
 State transitions are provided
within the response in
standardized format
 Document the general problem - a
domain – for creating solutions
Example
GET /orders/523 HTTP/1.1
Host: example.org
Accept: application/hal+json
HTTP/1.1 200 OK
Content-Type: application/hal+json
{
"_links": {
"self": { "href": "/orders/523" },
"warehouse": { "href": "/warehouse/56" },
"invoice": { "href": "/invoices/873" }
},
"currency": ”GBP",
"status": "shipped",
"total": 10.20
}
REST Maturity Model
XML-
RPC
SOAP
Level 0
Separ ate
R es our c es
Level 1
HTTP
VERBS
Level 2
Hyper
Media
Level 3
Documenting your API
What should you
document?
Cross cutting
concerns
HTTP status codes
HTTP verbs
Authentication &
authorization
Rate limiting
….
Resources
What do they
represent?
What input do they
accept?
What output do
they produce?
Links
Where can you
go?
What will you find
when you get
there?
What you should not
document?
URIs
REST API documentation
tools
Swagger
You can get lot of done with
little effort.
Hypermedia API and how to document it effectively
What’s wrong with
this type of documentation?
Swagger does not support
hypermedia
https :// github.com /s w agger -api /s w agger -core/is sues /97
It is URI centric
Lot of extra
stuff
It’s not DRY
Do we have a better option?
Spring REST Docs
Hand written documentation
+
auto generated snippets
produced with Spring MVC Test
Spring REST Docs
• Uses a format that is designed for
writing
• Doesn’t use implementation to
provide the documentation
• Provides some guarantees that
documentation is correct
What is needed?
• Asciidoctor
• Spring MVC test
• Maven or Gradle
Integration
Test
Generated
snippets
Manually
written
template
Generated
HTML
Integration Test
@Test
public void getOneArticle() throws Exception {
this.mockMvc.perform(get(“/osm/articles/{articleId}”,12)
.contextPath("/osm").accept(MediaTypes.HAL_JSON))
.andExpect(status().isOk())
.andDo(document("article-get-example",
pathParameters(
parameterWithName(“articleId”).description(“Article’s Id”)),
links(
linkWithRel(“self”).description(“Canonical link for this
<<resources-article, article>>”),
linkWithRel("delete-article").description("The link to delete
the article”)),
responseFields(
fieldWithPath("header").description(”Article’s header"),
fieldWithPath("body").description(”Article’s body"),
fieldWithPath("locale").description(”Article’s locale”))));
}
Request Snippets
Curl Request
HTTP Request
[source,bash]
----
$ curl 'http://localhost:8085/osm/articles/1' -i -H 'Accept: application/hal+json'
----
[source,http,options="nowrap"]
----
GET /osm/articles/1 HTTP/1.1
Accept: application/hal+json
Host: localhost:8085
----
Request Snippets
HTTPie Request
[source,bash]
----
$ http GET 'http://localhost:8085/osm/articles/1' 'Accept:application/hal+json'
----
Response snippet
[source,http,options="nowrap"]
----
HTTP/1.1 200 OK
ETag: "0"
Content-Type: application/hal+json;charset=UTF-8
Content-Length: 758
{
"header" : "testArticle",
"body" : "testBody",
"locale" : "en_GB",
"_links" : {
"self" : {
"href" : "http://localhost:8085/osm/articles/1"
},
"delete-article" : {
"href" : "http://localhost:8085/osm/articles/1"
}
}
}
----
Link snippet
|===
|Relation|Description
|`self`
|Canonical link for this <<resources-article, article>>
|`delete-article`
|The link to delete the article
|===
All different snippets
Request
Request Fields
Request Path
Parameters
Request Parameters
Request Headers
Request Parts
Response
Response Fields
Hypermedia Links
Response
Headers
Response Fields
Documentation Template
[[resources-article-retrieve]]
=== Retrieve an article
A `GET` request will retrieve the details of a article
==== Response structure
include::{snippets}/article-get-example/response-fields.adoc[]
==== Example request
include::{snippets}/article-get-example/curl-request.adoc[]
==== Example response
include::{snippets}/article-get-example/http-response.adoc[]
Thank You.
References:
http://docs.spring.io/spring-
restdocs/docs/1.1.2.RELEASE/reference/html5/
http://asciidoctor.org/

More Related Content

What's hot (7)

PPTX
ATAGTR2017 Machine Learning telepathy for Shift Right approach of testing
Agile Testing Alliance
 
PPT
The LEAD Portal: An OGCE based weather science gateway
marcuschristie
 
PPTX
STC Summit 2015: API Documentation, an Example-Based Approach
Lois Patterson
 
PPTX
ATAGTR2017 Analytics Testing
Agile Testing Alliance
 
PDF
The 7 Deadly Sins of API Design
luisw19
 
PDF
Unlock dependency between client teams and API team with API mock and proxy
Bruce Li
 
ODP
Creating Web Services with Zend Framework - Matthew Turland
Matthew Turland
 
ATAGTR2017 Machine Learning telepathy for Shift Right approach of testing
Agile Testing Alliance
 
The LEAD Portal: An OGCE based weather science gateway
marcuschristie
 
STC Summit 2015: API Documentation, an Example-Based Approach
Lois Patterson
 
ATAGTR2017 Analytics Testing
Agile Testing Alliance
 
The 7 Deadly Sins of API Design
luisw19
 
Unlock dependency between client teams and API team with API mock and proxy
Bruce Li
 
Creating Web Services with Zend Framework - Matthew Turland
Matthew Turland
 

Similar to Hypermedia API and how to document it effectively (20)

PDF
Netflix OSS and HATEOAS deployed on production - JavaLand
JWORKS powered by Ordina
 
PDF
Test-Driven Documentation for your REST(ful) service
Jeroen Reijn
 
PDF
Hypermedia api (HATEOAS)
MitinPavel
 
PPTX
dod-api-meetup-03262015-swagger-docs
John O'Brien III
 
PPTX
Making Sense of Hypermedia APIs – Hype or Reality?
Akana
 
PDF
Documenting RESTful APIs with Spring REST Docs
VMware Tanzu
 
PDF
Hypermedia APIs – Why, what, how?
Vesa Vänskä
 
PPTX
API workshop: Introduction to APIs (TC Camp)
Tom Johnson
 
PDF
Are hypermedia API's Just Hype?
Daniel Feist
 
PDF
Are Hypermedia APIs Just Hype? - Aaron Phethean (Temenos) & Daniel Feist (Mul...
jaxLondonConference
 
PDF
Microservices with Netflix OSS & Hypermedia APIs - JavaDay Kiev
JWORKS powered by Ordina
 
PDF
Swagger With REST APIs.pptx.pdf
Knoldus Inc.
 
PDF
Hypermedia APIs and HATEOAS
Vladimir Tsukur
 
PDF
API Docs Made Right / RAML - Swagger rant
Vladimir Shulyak
 
PDF
Intro to Hypermedia APIs
SmartLogic
 
PPTX
API Description Languages: Which is the Right One for Me?
Akana
 
PPTX
API Description Languages: Which is the Right One for Me?
Akana
 
PDF
Hypermedia APIs and HATEOAS / Wix Engineering
Vladimir Tsukur
 
PPTX
API Docs with OpenAPI 3.0
Fabrizio Ferri-Benedetti
 
PPTX
Documenting an API for the First Time? Quick-Start Tips for Your First API Do...
Petko Mikhailov
 
Netflix OSS and HATEOAS deployed on production - JavaLand
JWORKS powered by Ordina
 
Test-Driven Documentation for your REST(ful) service
Jeroen Reijn
 
Hypermedia api (HATEOAS)
MitinPavel
 
dod-api-meetup-03262015-swagger-docs
John O'Brien III
 
Making Sense of Hypermedia APIs – Hype or Reality?
Akana
 
Documenting RESTful APIs with Spring REST Docs
VMware Tanzu
 
Hypermedia APIs – Why, what, how?
Vesa Vänskä
 
API workshop: Introduction to APIs (TC Camp)
Tom Johnson
 
Are hypermedia API's Just Hype?
Daniel Feist
 
Are Hypermedia APIs Just Hype? - Aaron Phethean (Temenos) & Daniel Feist (Mul...
jaxLondonConference
 
Microservices with Netflix OSS & Hypermedia APIs - JavaDay Kiev
JWORKS powered by Ordina
 
Swagger With REST APIs.pptx.pdf
Knoldus Inc.
 
Hypermedia APIs and HATEOAS
Vladimir Tsukur
 
API Docs Made Right / RAML - Swagger rant
Vladimir Shulyak
 
Intro to Hypermedia APIs
SmartLogic
 
API Description Languages: Which is the Right One for Me?
Akana
 
API Description Languages: Which is the Right One for Me?
Akana
 
Hypermedia APIs and HATEOAS / Wix Engineering
Vladimir Tsukur
 
API Docs with OpenAPI 3.0
Fabrizio Ferri-Benedetti
 
Documenting an API for the First Time? Quick-Start Tips for Your First API Do...
Petko Mikhailov
 
Ad

More from Sanjoy Kumar Roy (8)

PPTX
Arch CoP - Domain Driven Design.pptx
Sanjoy Kumar Roy
 
PPTX
Visualizing Software Architecture Effectively in Service Description
Sanjoy Kumar Roy
 
PPTX
An introduction to OAuth 2
Sanjoy Kumar Roy
 
PPTX
Transaction
Sanjoy Kumar Roy
 
PPTX
Microservice architecture design principles
Sanjoy Kumar Roy
 
PPTX
Lessons learned in developing an agile architecture to reward our customers.
Sanjoy Kumar Roy
 
PPTX
An introduction to G1 collector for busy developers
Sanjoy Kumar Roy
 
PPT
Major Java 8 features
Sanjoy Kumar Roy
 
Arch CoP - Domain Driven Design.pptx
Sanjoy Kumar Roy
 
Visualizing Software Architecture Effectively in Service Description
Sanjoy Kumar Roy
 
An introduction to OAuth 2
Sanjoy Kumar Roy
 
Transaction
Sanjoy Kumar Roy
 
Microservice architecture design principles
Sanjoy Kumar Roy
 
Lessons learned in developing an agile architecture to reward our customers.
Sanjoy Kumar Roy
 
An introduction to G1 collector for busy developers
Sanjoy Kumar Roy
 
Major Java 8 features
Sanjoy Kumar Roy
 
Ad

Recently uploaded (20)

PPTX
Human Resources Information System (HRIS)
Amity University, Patna
 
PDF
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
PPTX
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
PPTX
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
PPTX
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
PPTX
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PDF
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
PDF
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
PPTX
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
PDF
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
PDF
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
PPTX
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
PPTX
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
PDF
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
PDF
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
PDF
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 
Human Resources Information System (HRIS)
Amity University, Patna
 
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Homogeneity of Variance Test Options IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
4K Video Downloader Plus Pro Crack for MacOS New Download 2025
bashirkhan333g
 

Hypermedia API and how to document it effectively

Editor's Notes

  • #5: This term is also coined by Ted Nelson.
  • #6: Architectural Styles and the Design of Network-based Software Architectures, Fielding's doctoral dissertation, describes Representational State Transfer (REST) as a key architectural principle of the World Wide Web. The architectural abstractions and constraints Roy Fielding established led to the introduction of HATEOAS.
  • #7: A distributed application makes forward progress by transitioning from one state to another, just like a state machine. The difference from traditional state machines, however, is that the possible states and the transitions between are not known in advance. Instead, as the application reaches a new state, the next possible transitions are discovered. It is like a treasure hunt. In a hypermedia system, application states are communicated through representations of uniquely identifiable resources. The identifiers of the states to which the application can transition are embedded in the representation of the current state in the form of links. This, in simple terms, is what the famous HATEOAS constraint is all about. We see it in action everyday on the Web, when we follow the links to other pages within our browser.
  • #8: Resources are the fundamental building blocks of the web-based system.  A resource can be anything that we expose to the Web. It can be a document or movie clip or a product or a business process. To use a resource like interacting with it on the network or manipulating it resource needs to be identifiable which means resource should get an ID. The web provides the URI (Uniform Resource Identifier) for this purpose. A URI uniquely identifies a web resource and at the same time makes it addressable. Examples of the URIs: http://example.com/customers/45679 , http://example.com/customers/45679/orders/123 . The relationship between URIs and resources is many to one. A URI identifies only one resource, but a resource can have more than one URI just like a human can have more than one email address or telephone number. A resource must have at least one identifier to be addressable on the web, and each identifier is associated with one or more representations. A representation is a transformation or a view of a resource’s state at an instant in time. It is important to remember that a resource can have one-to-many relationship with its representations. Resources need to be linked together. Server provides a set of links to the client that enables the client to move the application from one state to the next by following a link. Links make an application dynamic. It is the core concept of hypermedia: by transiting links between resources, we change the state of an application. There is a formal description of it: Hypermedia as the engine of application state (HATEOAS). The benefit of the link approach using URIs is that the links can point to the resources that can be provided by a different application, a different server, or event a different company. The standard HTTP methods like GET, PUT, POST, DELETE need to be used correctly in order to make the clients interact with the resources. These are also called HTTP verbs. For example, GET should be used to retrieve a representation of a resource. GET is safe and idempotent which means a same request to get a representation can be issued multiple times. PUT is for updating a resource with the data or create it at this URI if it is not there already. DELETE is for deleting a resource. Both are unsafe but idempotent. POST is for creating a new resource which is neither safe nor idempotent. When a safe method is invoked, the resource state on the server remains unchanged. An idempotent method can be invoked multiple times, the end result is the same. Following the HTTP methods correctly is important because this makes our application part of the web. In REST, the server should not have to retain some sort of communication state for any of the clients it communicates with beyond a single request. It decouples the clients from the server which improves the scalability.
  • #10: Here, we have a HAL document representing an order resource with the URI "/orders/523". It has "warehouse" and "invoice" links, and its own state in the form of "currency", "status", and "total" properties.
  • #28: By default four snippets get produced: curl-request.adoc http-request.adoc httpie-request.adoc http-response.adoc The above test will also produced another additional snippet related to request path parameters: path-parameters.adoc
  • #34: Documentation template is written using Asciidoctor. Spring Rest Docs uses Asciidoctor by default. Asciidoctor is a text processor and publishing toolchain for converting AsciiDoc (plain-text writing format) content to HTML5, DocBook 5 (or 4.5) and other formats. Asciidoctor is written in Ruby.