SlideShare a Scribd company logo
1 of 54
Download to read offline
Test-Driven Documentation
for your RESTful service
by Jeroen Reijn
JEROEN REIJN
Software Architect at Luminis /Amsterdam
• Focus on productivity and Developer Experience
• Been building APIs for the Web since 2010
• Writes most of his code in Java
• Tweets @jreijn
Let’s talk about Web APIs
source: https://www.programmableweb.com/
Streaming
1%
RPC
10%
REST
89%
REST RPC Streaming GraphQL
source: https://www.programmableweb.com/
REST
Source: http://geek-and-poke.com/geekandpoke/2013/6/14/insulting-made-easy
Richardson Maturity Model
Source: https://www.martinfowler.com/articles/richardsonMaturityModel.html
HATEOAS
(Hypermedia as the Engine of Application State)
REST
• Uniform interface
• Resources
• URIs
• Representations
• Hypermedia
Hypermedia
• Links in resource representations
• State navigations discoverable
Hypertext link specifications
• HAL
• JSON-LD
• JSON API
• Collection+JSON
• Siren
Hypertext link specifications
{
"_links" : {
"self" : {
"href" : "http://localhost:8080/"
},
"planets" : {
"href" : "http://localhost:8080/planets"
},
"people" : {
"href" : "http://localhost:8080/people"
}
}
}
Building an API
Design
BuildDocument
Let’s talk about API design
Specification driven
vs
Code driven
Specification Driven Design
Contract Driven Design
a.k.a
Manual spec
API design
RAML
• RESTful API Modelling Language (RAML)
• Based on YAML file format
• Powerful designer api with auto completion
• Code generation for Java
• No native support for HATEOAS
API Blueprint / Apiary
• Markdown flavoured syntax
• Powerful designer UI
• Documentation while designing
• Java code generator support is *very* minimal
Postman
• Postman client is great for testing APIs
• Supports designing & documenting APIs
• Has support for Api Mocks
• Enables fast prototyping of APIs
• Tools for different phases in the API lifecycle
Open API
• Widely adopted community-driven specification for REST APIs
• YAML and JSON based format
• Programming language-agnostic interface
• Allows both code first and contract first approaches to API design
• Evolving specification (version 3.0 released in the summer of 2017)
Swagger
• Tools around the OpenAPI specification
• Swagger editor
• Swagger-UI
• Swagger Codegen (server and client libs and many languages)
• Swagger Inspector
Swagger Codegen
/**
* Unique identifier representing a specific planet.
* @return id
**/
@ApiModelProperty(value = "Unique identifier representing a specific planet.")
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Planet name(String name) {
this.name = name;
return this;
}
Retrospect
• API Design tools and platform are getting really powerful
• OpenAPI seems to be the most widely adopted api spec
• Generating code from your API specification is up to you
Code Driven Design
“ An API is only as good 

as its documentation! ”
Let’s talk about API documentation
Manual documentation
Documentation based on specs
HTML / PDF
Docs based on code
@GetMapping(value = "/films/{id}")
ResponseEntity<Film> getFilmById(@PathVariable(“id") String id);
Docs based on code
@ApiOperation(value = "",
nickname = “getfilmbyid",
notes = "Get a specific film by id.",
response = Film.class,
authorizations = {
@Authorization(value = "apikeyQuery")
}, tags = {})
@ApiResponses(value = {
@ApiResponse(code = 200,
message = "A film.",
response = Film.class)})
@GetMapping(value = “/films/{id}")
ResponseEntity<Film> getFilmById(@ApiParam(value = "Id of the film.", required = true)
@PathVariable("id") String id);
Swagger drawbacks
• Hypermedia support not ‘final’
• Documentation is done through several annotations which are added in your
implementation classes
• API Implementation code overtime, gets overwhelmed with annotations
• Documentation is URI centric
• Documentation and API could become out-of-sync overtime
“ API documentation needs to be
more then just endpoints and
resources ”
Spring REST Docs
“Document RESTful services by combining 

hand-written documentation with 

auto-generated snippets 

produced with Spring MVC Test.”
Spring REST Docs
• Documentation is built from tests
• Supports hypermedia (HATEOAS) APIs
• Immediate reaction to API changes
• Keeps your code clean
• Produces AsciiDoc snippets
Basic Spring MVC Test
@Test
public void testGetAllPlanets() throws Exception {
mockMvc.perform(get("/planets").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("$.length()",is(2)));
}
With Spring REST Doc
@Test
public void testGetAllPlanets() throws Exception {
mockMvc.perform(get("/planets").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andExpect(jsonPath("$.length()",is(2)))
.andDo(document("planets/get"));
}
AsciiDoc snippets
|===
|Path|Type|Description
|`id`
|`Number`
|The id of the planet
|`name`
|`String`
|The name of the planet
|`diameter`
|`Number`
|The diameter of the planet
|===
AsciiDoc
Plain-text writing format. AsciiDoc documents can be translated into various formats, including
HTML, DocBook, PDF and ePub.
= Hello, DevCon!
Jeroen Reijn <jeroen.reijn@luminis.eu>
An introduction to documenting Hypermedia APIs with
https://projects.spring.io/spring-restdocs/[Spring REST Docs].
== First Section
* item 1
* item 2
Generating documentation
Test
Generated
snippets
AsciiDoctor pluginHand-written
docs
Code
Document
Let’s build an API!
Spring Auto REST Docs
• Extension for Spring REST Docs
• Response field documentation generated by means of introspection
• Partial support for documenting Hypermedia ‘links’ out of the box
• DRY - Uses JavaDoc for generating documentation
Spring REST Docs advantages
• Ability to focus on domain model rather than URI’s
• ‘Guarantees’ that API documentation and implementation code are in-sync
• Forces you to update documentation for any implementation changes
• Ability to document with different payloads and explain different test scenarios
• Ability to document remote APIs (with WebTestClient)
In retrospect
• Documenting Hypermedia API is getting easier
• Validating APIs against their documentation is still ‘hard’
• Spring REST Docs can help documenting and validating the API
• Good documentation is key to working with an API
Those who stand for nothing,
fall for anything - Alexander
Hamilton
?Thank you
Questions? is powered by
Don’t forget to vote!

More Related Content

What's hot

WinAppDriver Development
WinAppDriver DevelopmentWinAppDriver Development
WinAppDriver DevelopmentJeremy Kao
 
Angular 4 for Java Developers
Angular 4 for Java DevelopersAngular 4 for Java Developers
Angular 4 for Java DevelopersYakov Fain
 
SETCON'18 - Ilya labacheuski - GraphQL adventures
SETCON'18 - Ilya labacheuski - GraphQL adventuresSETCON'18 - Ilya labacheuski - GraphQL adventures
SETCON'18 - Ilya labacheuski - GraphQL adventuresNadzeya Pus
 
Modern Tools for API Testing, Debugging and Monitoring
Modern Tools for API Testing, Debugging and MonitoringModern Tools for API Testing, Debugging and Monitoring
Modern Tools for API Testing, Debugging and MonitoringNeil Mansilla
 
Introduction to React Native
Introduction to React NativeIntroduction to React Native
Introduction to React NativePolidea
 
Exploring Angular 2 - Episode 1
Exploring Angular 2 - Episode 1Exploring Angular 2 - Episode 1
Exploring Angular 2 - Episode 1Ahmed Moawad
 
React Native custom components
React Native custom componentsReact Native custom components
React Native custom componentsJeremy Grancher
 
Scala Italy 2015 - Hands On ScalaJS
Scala Italy 2015 - Hands On ScalaJSScala Italy 2015 - Hands On ScalaJS
Scala Italy 2015 - Hands On ScalaJSAlberto Paro
 
OpenAPI development with Python
OpenAPI development with PythonOpenAPI development with Python
OpenAPI development with PythonTakuro Wada
 
Having fun with code igniter
Having fun with code igniterHaving fun with code igniter
Having fun with code igniterAhmad Arif
 
Introduction to React Native
Introduction to React NativeIntroduction to React Native
Introduction to React NativeRami Sayar
 
Google Cloud Endpoints: Building Third-Party APIs on Google AppEngine
Google Cloud Endpoints: Building Third-Party APIs on Google AppEngineGoogle Cloud Endpoints: Building Third-Party APIs on Google AppEngine
Google Cloud Endpoints: Building Third-Party APIs on Google AppEngineRoman Kirillov
 
GraphQL in an Age of REST
GraphQL in an Age of RESTGraphQL in an Age of REST
GraphQL in an Age of RESTYos Riady
 

What's hot (20)

WinAppDriver Development
WinAppDriver DevelopmentWinAppDriver Development
WinAppDriver Development
 
Angular 4 for Java Developers
Angular 4 for Java DevelopersAngular 4 for Java Developers
Angular 4 for Java Developers
 
PyUIA 0.3
PyUIA 0.3PyUIA 0.3
PyUIA 0.3
 
Laravel 5 and SOLID
Laravel 5 and SOLIDLaravel 5 and SOLID
Laravel 5 and SOLID
 
SETCON'18 - Ilya labacheuski - GraphQL adventures
SETCON'18 - Ilya labacheuski - GraphQL adventuresSETCON'18 - Ilya labacheuski - GraphQL adventures
SETCON'18 - Ilya labacheuski - GraphQL adventures
 
[2015/2016] JavaScript
[2015/2016] JavaScript[2015/2016] JavaScript
[2015/2016] JavaScript
 
Modern Tools for API Testing, Debugging and Monitoring
Modern Tools for API Testing, Debugging and MonitoringModern Tools for API Testing, Debugging and Monitoring
Modern Tools for API Testing, Debugging and Monitoring
 
Introduction to React Native
Introduction to React NativeIntroduction to React Native
Introduction to React Native
 
Exploring Angular 2 - Episode 1
Exploring Angular 2 - Episode 1Exploring Angular 2 - Episode 1
Exploring Angular 2 - Episode 1
 
React Native custom components
React Native custom componentsReact Native custom components
React Native custom components
 
Scala Italy 2015 - Hands On ScalaJS
Scala Italy 2015 - Hands On ScalaJSScala Italy 2015 - Hands On ScalaJS
Scala Italy 2015 - Hands On ScalaJS
 
Angular js for Beginnners
Angular js for BeginnnersAngular js for Beginnners
Angular js for Beginnners
 
OpenAPI development with Python
OpenAPI development with PythonOpenAPI development with Python
OpenAPI development with Python
 
Having fun with code igniter
Having fun with code igniterHaving fun with code igniter
Having fun with code igniter
 
Introduction to React Native
Introduction to React NativeIntroduction to React Native
Introduction to React Native
 
Google Cloud Endpoints: Building Third-Party APIs on Google AppEngine
Google Cloud Endpoints: Building Third-Party APIs on Google AppEngineGoogle Cloud Endpoints: Building Third-Party APIs on Google AppEngine
Google Cloud Endpoints: Building Third-Party APIs on Google AppEngine
 
Angular 4
Angular 4Angular 4
Angular 4
 
Workshop 15: Ionic framework
Workshop 15: Ionic frameworkWorkshop 15: Ionic framework
Workshop 15: Ionic framework
 
GraphQL
GraphQLGraphQL
GraphQL
 
GraphQL in an Age of REST
GraphQL in an Age of RESTGraphQL in an Age of REST
GraphQL in an Age of REST
 

Similar to Test-Driven Documentation for your REST(ful) service

API workshop: Introduction to APIs (TC Camp)
API workshop: Introduction to APIs (TC Camp)API workshop: Introduction to APIs (TC Camp)
API workshop: Introduction to APIs (TC Camp)Tom Johnson
 
Play Support in Cloud Foundry
Play Support in Cloud FoundryPlay Support in Cloud Foundry
Play Support in Cloud Foundryrajdeep
 
Building Better Web APIs with Rails
Building Better Web APIs with RailsBuilding Better Web APIs with Rails
Building Better Web APIs with RailsAll Things Open
 
Entity provider selection confusion attacks in JAX-RS applications
Entity provider selection confusion attacks in JAX-RS applicationsEntity provider selection confusion attacks in JAX-RS applications
Entity provider selection confusion attacks in JAX-RS applicationsMikhail Egorov
 
SharePoint 2013 APIs
SharePoint 2013 APIsSharePoint 2013 APIs
SharePoint 2013 APIsJohn Calvert
 
GraphQL: The Missing Link Between Frontend and Backend Devs
GraphQL: The Missing Link Between Frontend and Backend DevsGraphQL: The Missing Link Between Frontend and Backend Devs
GraphQL: The Missing Link Between Frontend and Backend DevsSashko Stubailo
 
Angular for Java Enterprise Developers: Oracle Code One 2018
Angular for Java Enterprise Developers: Oracle Code One 2018Angular for Java Enterprise Developers: Oracle Code One 2018
Angular for Java Enterprise Developers: Oracle Code One 2018Loiane Groner
 
Survival Strategies for API Documentation: Presentation to Southwestern Ontar...
Survival Strategies for API Documentation: Presentation to Southwestern Ontar...Survival Strategies for API Documentation: Presentation to Southwestern Ontar...
Survival Strategies for API Documentation: Presentation to Southwestern Ontar...Tom Johnson
 
Spring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. RESTSpring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. RESTSam Brannen
 
Intro to node.js - Ran Mizrahi (27/8/2014)
Intro to node.js - Ran Mizrahi (27/8/2014)Intro to node.js - Ran Mizrahi (27/8/2014)
Intro to node.js - Ran Mizrahi (27/8/2014)Ran Mizrahi
 
Intro to node.js - Ran Mizrahi (28/8/14)
Intro to node.js - Ran Mizrahi (28/8/14)Intro to node.js - Ran Mizrahi (28/8/14)
Intro to node.js - Ran Mizrahi (28/8/14)Ran Mizrahi
 
Ibm_interconnect_restapi_workshop
Ibm_interconnect_restapi_workshopIbm_interconnect_restapi_workshop
Ibm_interconnect_restapi_workshopShubhra Kar
 
Swagger - make your API accessible
Swagger - make your API accessibleSwagger - make your API accessible
Swagger - make your API accessibleVictor Trakhtenberg
 
Sinergija2012 - Developing REST API for Windows Azure with ASP.NET Web API
Sinergija2012 - Developing REST API for Windows Azure with ASP.NET Web APISinergija2012 - Developing REST API for Windows Azure with ASP.NET Web API
Sinergija2012 - Developing REST API for Windows Azure with ASP.NET Web APIRadenko Zec
 
Building APIs in an easy way using API Platform
Building APIs in an easy way using API PlatformBuilding APIs in an easy way using API Platform
Building APIs in an easy way using API PlatformAntonio Peric-Mazar
 
ASP.NET Core 1.0
ASP.NET Core 1.0ASP.NET Core 1.0
ASP.NET Core 1.0Ido Flatow
 

Similar to Test-Driven Documentation for your REST(ful) service (20)

API workshop: Introduction to APIs (TC Camp)
API workshop: Introduction to APIs (TC Camp)API workshop: Introduction to APIs (TC Camp)
API workshop: Introduction to APIs (TC Camp)
 
Play Support in Cloud Foundry
Play Support in Cloud FoundryPlay Support in Cloud Foundry
Play Support in Cloud Foundry
 
Building Better Web APIs with Rails
Building Better Web APIs with RailsBuilding Better Web APIs with Rails
Building Better Web APIs with Rails
 
Entity provider selection confusion attacks in JAX-RS applications
Entity provider selection confusion attacks in JAX-RS applicationsEntity provider selection confusion attacks in JAX-RS applications
Entity provider selection confusion attacks in JAX-RS applications
 
Graphql usage
Graphql usageGraphql usage
Graphql usage
 
Andrei shakirin rest_cxf
Andrei shakirin rest_cxfAndrei shakirin rest_cxf
Andrei shakirin rest_cxf
 
SharePoint 2013 APIs
SharePoint 2013 APIsSharePoint 2013 APIs
SharePoint 2013 APIs
 
GraphQL: The Missing Link Between Frontend and Backend Devs
GraphQL: The Missing Link Between Frontend and Backend DevsGraphQL: The Missing Link Between Frontend and Backend Devs
GraphQL: The Missing Link Between Frontend and Backend Devs
 
Angular for Java Enterprise Developers: Oracle Code One 2018
Angular for Java Enterprise Developers: Oracle Code One 2018Angular for Java Enterprise Developers: Oracle Code One 2018
Angular for Java Enterprise Developers: Oracle Code One 2018
 
Survival Strategies for API Documentation: Presentation to Southwestern Ontar...
Survival Strategies for API Documentation: Presentation to Southwestern Ontar...Survival Strategies for API Documentation: Presentation to Southwestern Ontar...
Survival Strategies for API Documentation: Presentation to Southwestern Ontar...
 
Spring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. RESTSpring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. REST
 
Intro to node.js - Ran Mizrahi (27/8/2014)
Intro to node.js - Ran Mizrahi (27/8/2014)Intro to node.js - Ran Mizrahi (27/8/2014)
Intro to node.js - Ran Mizrahi (27/8/2014)
 
Intro to node.js - Ran Mizrahi (28/8/14)
Intro to node.js - Ran Mizrahi (28/8/14)Intro to node.js - Ran Mizrahi (28/8/14)
Intro to node.js - Ran Mizrahi (28/8/14)
 
Ibm_interconnect_restapi_workshop
Ibm_interconnect_restapi_workshopIbm_interconnect_restapi_workshop
Ibm_interconnect_restapi_workshop
 
Swagger - make your API accessible
Swagger - make your API accessibleSwagger - make your API accessible
Swagger - make your API accessible
 
RESTing with JAX-RS
RESTing with JAX-RSRESTing with JAX-RS
RESTing with JAX-RS
 
Sinergija2012 - Developing REST API for Windows Azure with ASP.NET Web API
Sinergija2012 - Developing REST API for Windows Azure with ASP.NET Web APISinergija2012 - Developing REST API for Windows Azure with ASP.NET Web API
Sinergija2012 - Developing REST API for Windows Azure with ASP.NET Web API
 
Introduction to Flask Micro Framework
Introduction to Flask Micro FrameworkIntroduction to Flask Micro Framework
Introduction to Flask Micro Framework
 
Building APIs in an easy way using API Platform
Building APIs in an easy way using API PlatformBuilding APIs in an easy way using API Platform
Building APIs in an easy way using API Platform
 
ASP.NET Core 1.0
ASP.NET Core 1.0ASP.NET Core 1.0
ASP.NET Core 1.0
 

More from Jeroen Reijn

Hoe releasen minder pijnlijk werd bij de ANWB Alarmcentrale
Hoe releasen minder pijnlijk werd bij de ANWB AlarmcentraleHoe releasen minder pijnlijk werd bij de ANWB Alarmcentrale
Hoe releasen minder pijnlijk werd bij de ANWB AlarmcentraleJeroen Reijn
 
Continuous Delivery in a content centric world
Continuous Delivery in a content centric worldContinuous Delivery in a content centric world
Continuous Delivery in a content centric worldJeroen Reijn
 
Hippo CMS Integration Patterns
Hippo CMS Integration PatternsHippo CMS Integration Patterns
Hippo CMS Integration PatternsJeroen Reijn
 
Real-time visitor analysis with Couchbase and Elastichsearch
Real-time visitor analysis with Couchbase and ElastichsearchReal-time visitor analysis with Couchbase and Elastichsearch
Real-time visitor analysis with Couchbase and ElastichsearchJeroen Reijn
 
Shootout! Template engines for the JVM
Shootout! Template engines for the JVMShootout! Template engines for the JVM
Shootout! Template engines for the JVMJeroen Reijn
 
Hippo GetTogether: The architecture behind Hippos relevance platform
Hippo GetTogether: The architecture behind Hippos relevance platformHippo GetTogether: The architecture behind Hippos relevance platform
Hippo GetTogether: The architecture behind Hippos relevance platformJeroen Reijn
 
Building a relevance platform with Couchbase and Elasticsearch
Building a relevance platform with Couchbase and ElasticsearchBuilding a relevance platform with Couchbase and Elasticsearch
Building a relevance platform with Couchbase and ElasticsearchJeroen Reijn
 
Basic web application development with Apache Cocoon 2.1
Basic web application development with  Apache Cocoon 2.1Basic web application development with  Apache Cocoon 2.1
Basic web application development with Apache Cocoon 2.1Jeroen Reijn
 

More from Jeroen Reijn (8)

Hoe releasen minder pijnlijk werd bij de ANWB Alarmcentrale
Hoe releasen minder pijnlijk werd bij de ANWB AlarmcentraleHoe releasen minder pijnlijk werd bij de ANWB Alarmcentrale
Hoe releasen minder pijnlijk werd bij de ANWB Alarmcentrale
 
Continuous Delivery in a content centric world
Continuous Delivery in a content centric worldContinuous Delivery in a content centric world
Continuous Delivery in a content centric world
 
Hippo CMS Integration Patterns
Hippo CMS Integration PatternsHippo CMS Integration Patterns
Hippo CMS Integration Patterns
 
Real-time visitor analysis with Couchbase and Elastichsearch
Real-time visitor analysis with Couchbase and ElastichsearchReal-time visitor analysis with Couchbase and Elastichsearch
Real-time visitor analysis with Couchbase and Elastichsearch
 
Shootout! Template engines for the JVM
Shootout! Template engines for the JVMShootout! Template engines for the JVM
Shootout! Template engines for the JVM
 
Hippo GetTogether: The architecture behind Hippos relevance platform
Hippo GetTogether: The architecture behind Hippos relevance platformHippo GetTogether: The architecture behind Hippos relevance platform
Hippo GetTogether: The architecture behind Hippos relevance platform
 
Building a relevance platform with Couchbase and Elasticsearch
Building a relevance platform with Couchbase and ElasticsearchBuilding a relevance platform with Couchbase and Elasticsearch
Building a relevance platform with Couchbase and Elasticsearch
 
Basic web application development with Apache Cocoon 2.1
Basic web application development with  Apache Cocoon 2.1Basic web application development with  Apache Cocoon 2.1
Basic web application development with Apache Cocoon 2.1
 

Recently uploaded

Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
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
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
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
 
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
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
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
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningVitsRangannavar
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 

Recently uploaded (20)

Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
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...
 
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)
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
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
 
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
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
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
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learning
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 

Test-Driven Documentation for your REST(ful) service

  • 1. Test-Driven Documentation for your RESTful service by Jeroen Reijn
  • 2. JEROEN REIJN Software Architect at Luminis /Amsterdam • Focus on productivity and Developer Experience • Been building APIs for the Web since 2010 • Writes most of his code in Java • Tweets @jreijn
  • 5. Streaming 1% RPC 10% REST 89% REST RPC Streaming GraphQL source: https://www.programmableweb.com/
  • 8. Richardson Maturity Model Source: https://www.martinfowler.com/articles/richardsonMaturityModel.html HATEOAS (Hypermedia as the Engine of Application State)
  • 9. REST • Uniform interface • Resources • URIs • Representations • Hypermedia
  • 10. Hypermedia • Links in resource representations • State navigations discoverable
  • 11. Hypertext link specifications • HAL • JSON-LD • JSON API • Collection+JSON • Siren
  • 12. Hypertext link specifications { "_links" : { "self" : { "href" : "http://localhost:8080/" }, "planets" : { "href" : "http://localhost:8080/planets" }, "people" : { "href" : "http://localhost:8080/people" } } }
  • 14. Let’s talk about API design
  • 19. RAML • RESTful API Modelling Language (RAML) • Based on YAML file format • Powerful designer api with auto completion • Code generation for Java • No native support for HATEOAS
  • 20.
  • 21. API Blueprint / Apiary • Markdown flavoured syntax • Powerful designer UI • Documentation while designing • Java code generator support is *very* minimal
  • 22.
  • 23. Postman • Postman client is great for testing APIs • Supports designing & documenting APIs • Has support for Api Mocks • Enables fast prototyping of APIs • Tools for different phases in the API lifecycle
  • 24.
  • 25. Open API • Widely adopted community-driven specification for REST APIs • YAML and JSON based format • Programming language-agnostic interface • Allows both code first and contract first approaches to API design • Evolving specification (version 3.0 released in the summer of 2017)
  • 26. Swagger • Tools around the OpenAPI specification • Swagger editor • Swagger-UI • Swagger Codegen (server and client libs and many languages) • Swagger Inspector
  • 27.
  • 28.
  • 29. Swagger Codegen /** * Unique identifier representing a specific planet. * @return id **/ @ApiModelProperty(value = "Unique identifier representing a specific planet.") public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public Planet name(String name) { this.name = name; return this; }
  • 30. Retrospect • API Design tools and platform are getting really powerful • OpenAPI seems to be the most widely adopted api spec • Generating code from your API specification is up to you
  • 32.
  • 33. “ An API is only as good 
 as its documentation! ”
  • 34. Let’s talk about API documentation
  • 35.
  • 37. Documentation based on specs HTML / PDF
  • 38. Docs based on code @GetMapping(value = "/films/{id}") ResponseEntity<Film> getFilmById(@PathVariable(“id") String id);
  • 39. Docs based on code @ApiOperation(value = "", nickname = “getfilmbyid", notes = "Get a specific film by id.", response = Film.class, authorizations = { @Authorization(value = "apikeyQuery") }, tags = {}) @ApiResponses(value = { @ApiResponse(code = 200, message = "A film.", response = Film.class)}) @GetMapping(value = “/films/{id}") ResponseEntity<Film> getFilmById(@ApiParam(value = "Id of the film.", required = true) @PathVariable("id") String id);
  • 40.
  • 41. Swagger drawbacks • Hypermedia support not ‘final’ • Documentation is done through several annotations which are added in your implementation classes • API Implementation code overtime, gets overwhelmed with annotations • Documentation is URI centric • Documentation and API could become out-of-sync overtime
  • 42. “ API documentation needs to be more then just endpoints and resources ”
  • 43. Spring REST Docs “Document RESTful services by combining 
 hand-written documentation with 
 auto-generated snippets 
 produced with Spring MVC Test.”
  • 44. Spring REST Docs • Documentation is built from tests • Supports hypermedia (HATEOAS) APIs • Immediate reaction to API changes • Keeps your code clean • Produces AsciiDoc snippets
  • 45. Basic Spring MVC Test @Test public void testGetAllPlanets() throws Exception { mockMvc.perform(get("/planets").accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("$.length()",is(2))); }
  • 46. With Spring REST Doc @Test public void testGetAllPlanets() throws Exception { mockMvc.perform(get("/planets").accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("$.length()",is(2))) .andDo(document("planets/get")); }
  • 47. AsciiDoc snippets |=== |Path|Type|Description |`id` |`Number` |The id of the planet |`name` |`String` |The name of the planet |`diameter` |`Number` |The diameter of the planet |===
  • 48. AsciiDoc Plain-text writing format. AsciiDoc documents can be translated into various formats, including HTML, DocBook, PDF and ePub. = Hello, DevCon! Jeroen Reijn <jeroen.reijn@luminis.eu> An introduction to documenting Hypermedia APIs with https://projects.spring.io/spring-restdocs/[Spring REST Docs]. == First Section * item 1 * item 2
  • 51. Spring Auto REST Docs • Extension for Spring REST Docs • Response field documentation generated by means of introspection • Partial support for documenting Hypermedia ‘links’ out of the box • DRY - Uses JavaDoc for generating documentation
  • 52. Spring REST Docs advantages • Ability to focus on domain model rather than URI’s • ‘Guarantees’ that API documentation and implementation code are in-sync • Forces you to update documentation for any implementation changes • Ability to document with different payloads and explain different test scenarios • Ability to document remote APIs (with WebTestClient)
  • 53. In retrospect • Documenting Hypermedia API is getting easier • Validating APIs against their documentation is still ‘hard’ • Spring REST Docs can help documenting and validating the API • Good documentation is key to working with an API
  • 54. Those who stand for nothing, fall for anything - Alexander Hamilton ?Thank you Questions? is powered by Don’t forget to vote!