SlideShare uma empresa Scribd logo
1 de 38
Baixar para ler offline
miredotmiredot
miredot
RESTful API Design and Documentation – an Introduction
BeJUG April 2016
miredotmiredotmiredot
Agenda
REST – What and Why?
Basic REST Design Principles
Documenting a REST API
Quick Demos
Miredot
POST https://api.twitter.com/tweets
{
“status”: “Great to be at BeJUG"
}
POST https://api.twitter.com/1.1/statuses/update.json?status=Great%20to%20be%at%BeJUG
*
**
miredotmiredotmiredot
REST – What and Why?
REpresentational State Transfer
Things/resources instead actions (SOAP/RPC)
Using HTTP the right way
Stateless (if possible)
Cache-able, Firewall-able, Proxy-able
(JSON)
For purists: know the initial URI and navigate via hyperlinks (HATEAOS)
miredotmiredot
miredotmiredotmiredot
REST Design Principles
Religiously RESTful vs REST-like
Goals
1. Easy to use API
2. Predictable behavior
3. Works with existing infrastructure (proxies, browsers)
Don’t think Java, think API first!
miredotmiredotmiredot
REST Design Principles – URI / Resource
https://api.acme.com/petstore/dogs/5/toys/2/parts
base URL
all the dogs
dog with id=5
toy with id=2
all the toys of dog 5
all the parts of toy 2
?material=plastic
Rule1: Plural for collections, ID for single element
Rule2: No verbs! ../petstore/dogs/add
Rule3: Query params only for meta-info (filtering, format)
extra info
miredotmiredotmiredot
REST Design Principles – Operations
Choose your operation wisely!
POST /dogs/5/toys
PUT /dogs/5/toys/2
GET /dogs/5
GET /dogs?fur=brown
DELETE /dogs/5/toys/2
Give dog 5 a new toy
Change something about his toy
Get all data of dog 5
Get all dogs called Snoopy
Take away his toy
POST = Create
PUT = Update (or create)
GET = Read
DELETE = Delete
miredotmiredotmiredot
REST Design Principles – Operations
Choose your operation wisely!
POST /dogs/5/toys
PUT /dogs/5/toys/2
GET /dogs/5
GET /dogs?fur=brown
DELETE /dogs/5/toys/2
Give dog 5 a new toy
Change something about his toy
Get all data of dog 5
Get all dogs called Snoopy
Take away his toy
201 CREATED
“2”
{
“name”: “chicken”
}
request response
miredotmiredotmiredot
REST Design Principles – Operations
Choose your operation wisely!
POST /dogs/5/toys
PUT /dogs/5/toys/2
GET /dogs/5
GET /dogs?fur=brown
DELETE /dogs/5/toys/2
Give dog 5 a new toy
Change something about his toy
Get all data of dog 5
Get all dogs called Snoopy
Take away his toy
200 OK{
“name”: “duck”
}
request response
miredotmiredotmiredot
REST Design Principles – Operations
Choose your operation wisely!
POST /dogs/5/toys
PUT /dogs/5/toys/2
GET /dogs/5
GET /dogs?fur=brown
DELETE /dogs/5/toys/2
Give dog 5 a new toy
Change something about his toy
Get all data of dog 5
Get all dogs called Snoopy
Take away his toy
200 OK
{
“name”: “Snoopy”
“favouriteToy”: 2
}
N/A
request response
miredotmiredotmiredot
REST Design Principles – Operations
Choose your operation wisely!
POST /dogs/5/toys
PUT /dogs/5/toys/2
GET /dogs/5
GET /dogs?fur=brown
DELETE /dogs/5/toys/2
Give dog 5 a new toy
Change something about his toy
Get all data of dog 5
Get all dogs called Snoopy
Take away his toy
200 OK
[{ “name”: “Scooby Doo” },
{ “name”: “Lassie” }]
N/A
request response
miredotmiredotmiredot
REST Design Principles – Operations
Choose your operation wisely!
POST /dogs/5/toys
PUT /dogs/5/toys/2
GET /dogs/5
GET /dogs?fur=brown
DELETE /dogs/5/toys/2
Give dog 5 a new toy
Change something about his toy
Get all data of dog 5
Get all dogs called Snoopy
Take away his toy
200 NO CONTENTN/A
request response
miredotmiredotmiredot
REST Design Principles – Operations
Choose your operation wisely!
POST /dogs/5/toys
PUT /dogs/5/toys/2
GET /dogs/5
GET /dogs?fur=brown
DELETE /dogs/5/toys/2
Rule1: GET is readonly, has no side effects (, cacheable)
Rule2: POST creates, PUT creates or updates
Rule3: GET/PUT/DELETE are idempotent
Give dog 5 a new toy
Change something about his toy
Get all data of dog 5
Get all dogs called Snoopy
Take away his toy
miredotmiredotmiredot
REST Design Principles
See http://www.miredot.com/blog/posts/rest-api-design-basic-rules/
miredotmiredot
miredotmiredotmiredot
REST API Issues
GET has a side-effect
Never do this as this is often cached, pre-fetched, etc.
Will cause hard to debug problems
GET /accounts/3/balance à Wires €10 to Acme company
GET /accounts/3/balance
GET /accounts/3/balance
GET /accounts/3/balance
GET /accounts/3/balance
à Wires €10 to Acme company
à Wires €10 to Acme company
…
miredotmiredotmiredot
REST API Issues
Data in query parameters
POST https://api.twitter.com/statuses/update?status=Great%20to%20be%at%BeJUG
POST //api.twitter.com/statuses/
{
“status”: “Great to be at BEJUG”
}
PUT //api.twitter.com/statuses/4
{
“status” : “Great to be at BEJUG”
}
Client-generated ID
miredotmiredotmiredot
REST API Issues
Verbs in the resource path
Failed form of RPC
/getAccount
/createDirectory
/group/update
/dogs/4/bark
GET PUT POST ?
miredotmiredotmiredot
REST API Issues
How do I make a dog bark?
POST /dogs/5/bark
POST /dogs/5/commands/
{
“command”: “bark”
}
GET /dogs/5/commands/1
{
“id”: 1,
“command”: “bark”,
“status”: “executed”,
“time”: “2016-04-19”
}
Optional
Reify the action à commands
miredotmiredotmiredot
REST Design Principles – Other considerations
Payloads (prefer JSON)
Big vs small, field naming: be consistent
(HATEOAS)
Representation: one resource, multiple formats
Accept and content-type headers
Versioning
Header, accept/content-type, URL
Security
Oauth, don’t invent your own
miredotmiredotmiredot
Implementing REST in Java
Jax-rs
Spring-mvc
miredotmiredotmiredot
Take care of your API
It’s the user interface of your service
Be API-centric, not Java-centric!
Design your API with the whole team
Review your API regularly
Be consistent above all
miredotmiredot
miredotmiredotmiredot
How Important is API Documentation?
For private APIs: VERY
I DON’T want to look at your source code
For public APIs: Didn’t find a word to describe
Developers will hate your API, you and your company.
miredotmiredotmiredot
Three Approaches
Write it yourself
Wikis, Word, Web-page
Dedicated Wikis
API Specification Language
RAML, API Blueprint, Swagger
Generate
Miredot, Enunciate, Swagger, JsonDoc, APIDoc
miredotmiredotmiredot
Write yourself
1.  Word: DON’T
2.  Wiki: avoid
3.  readme.io, gelato.io: Nice docs, flexible
REST/JSON-editor
Import from Apiary, RAML, Swagger
Hard to maintain
Very hard to test
(Never in sync with the implementation)
miredotmiredot
miredotmiredotmiredot
API Specification Language
API First: focus on design
RAML, SwaggerSpec, API Blueprint (Apiary)
Cross-language, cross-framework
Hard to maintain
Test your API through the spec: hard
miredotmiredotmiredot
RAML
Mulesoft, Anypoint platform
YAML based, very modular
Many tools, plugins: generate
clients, documentation, parser,
validator
Varying quality
API Specification Language
Swagger (2.0)
Smart Bear, Open API initiative
Both a spec and tooling, also YAML
Comes with core tooling (Swagger
UI), several open source tools
SwaggerUI: runtime component,
interactive documentation
More closely integration in your project (also Java)
miredotmiredotmiredot
API Specification Language
miredotmiredotmiredot
API Specification Language
miredotmiredotmiredot
Generators
Get documentation for free
Is my language / are my frameworks supported?
Jax-rs, Spring-mvc / Jackson, Gson
Is the output correct?
Does it understand all my Java code (types, generics, frameworks)?
Do I need to add anything to my code?
Documentation always in sync with implementation
Sit back and relax
miredotmiredotmiredot
Enunciate
One of the first generators for Java
Supported frameworks
Jax-rs
Outputs
Website, client libraries, WSDL, WADL
Swagger
Supported frameworks
Jax-rs (very limited), Spring-mvc (via SpringFox)
Requires its own annotations
Outputs
Website, interactive api client, client libraries, server
stubs
miredotmiredotmiredot
Miredot
We were not satisfied with existing generators
Don’t support all Java constructs (generics, inheritance, …) or frameworks
Hard to setup (hours/days)
Java Support
Full Jax-rs, Spring-mvc, Jackson, RestEasy, Guava, …
Generics, inheritance, Optionals, Guava, …
Outputs
Website (static), Word, RAML
Documentation quality reporting
miredotmiredotmiredot
Demo
Swagger, Miredot
miredotmiredotmiredot
Miredot
Free for open source, subscription for commercial projects
Pay-per-endpoint
Roadmap
Documentation Quality Dashboard (Sonar-like)
Version compatibility checking
miredotmiredotmiredot
Final Words
1.  Carefully design your API, you’ll be stuck with it for a long time
2.  Don’t let documentation be an afterthought: start from day one
3.  Use the many tools that are out there, they help a lot!
miredotmiredot
www.miredot.com
bert.vanhooff@miredot.com
yves.vandewoude@miredot.com
miredot
Thank you!
try

Mais conteúdo relacionado

Mais procurados

XML External Entity (XXE)
XML External Entity (XXE)XML External Entity (XXE)
XML External Entity (XXE)Jay Thakker
 
What is REST API? REST API Concepts and Examples | Edureka
What is REST API? REST API Concepts and Examples | EdurekaWhat is REST API? REST API Concepts and Examples | Edureka
What is REST API? REST API Concepts and Examples | EdurekaEdureka!
 
Neat tricks to bypass CSRF-protection
Neat tricks to bypass CSRF-protectionNeat tricks to bypass CSRF-protection
Neat tricks to bypass CSRF-protectionMikhail Egorov
 
Integration patterns in AEM 6
Integration patterns in AEM 6Integration patterns in AEM 6
Integration patterns in AEM 6Yuval Ararat
 
Understanding REST APIs in 5 Simple Steps
Understanding REST APIs in 5 Simple StepsUnderstanding REST APIs in 5 Simple Steps
Understanding REST APIs in 5 Simple StepsTessa Mero
 
Introduction to the Web API
Introduction to the Web APIIntroduction to the Web API
Introduction to the Web APIBrad Genereaux
 
CSRF, ClickJacking & Open Redirect
CSRF, ClickJacking & Open RedirectCSRF, ClickJacking & Open Redirect
CSRF, ClickJacking & Open RedirectBlueinfy Solutions
 
REST API and CRUD
REST API and CRUDREST API and CRUD
REST API and CRUDPrem Sanil
 
Reverse proxies & Inconsistency
Reverse proxies & InconsistencyReverse proxies & Inconsistency
Reverse proxies & InconsistencyGreenD0g
 
Reverse Engineering iOS apps
Reverse Engineering iOS appsReverse Engineering iOS apps
Reverse Engineering iOS appsMax Bazaliy
 
HTML 5 & WebGL (Spanish Version)
HTML 5 & WebGL (Spanish Version)HTML 5 & WebGL (Spanish Version)
HTML 5 & WebGL (Spanish Version)Iran Reyes Fleitas
 
REST API Design & Development
REST API Design & DevelopmentREST API Design & Development
REST API Design & DevelopmentAshok Pundit
 

Mais procurados (20)

XML External Entity (XXE)
XML External Entity (XXE)XML External Entity (XXE)
XML External Entity (XXE)
 
REST & RESTful Web Services
REST & RESTful Web ServicesREST & RESTful Web Services
REST & RESTful Web Services
 
What is REST API? REST API Concepts and Examples | Edureka
What is REST API? REST API Concepts and Examples | EdurekaWhat is REST API? REST API Concepts and Examples | Edureka
What is REST API? REST API Concepts and Examples | Edureka
 
Neat tricks to bypass CSRF-protection
Neat tricks to bypass CSRF-protectionNeat tricks to bypass CSRF-protection
Neat tricks to bypass CSRF-protection
 
Integration patterns in AEM 6
Integration patterns in AEM 6Integration patterns in AEM 6
Integration patterns in AEM 6
 
Understanding REST APIs in 5 Simple Steps
Understanding REST APIs in 5 Simple StepsUnderstanding REST APIs in 5 Simple Steps
Understanding REST APIs in 5 Simple Steps
 
Introduction to the Web API
Introduction to the Web APIIntroduction to the Web API
Introduction to the Web API
 
Rest api and-crud-api
Rest api and-crud-apiRest api and-crud-api
Rest api and-crud-api
 
CSRF, ClickJacking & Open Redirect
CSRF, ClickJacking & Open RedirectCSRF, ClickJacking & Open Redirect
CSRF, ClickJacking & Open Redirect
 
REST API and CRUD
REST API and CRUDREST API and CRUD
REST API and CRUD
 
Web api
Web apiWeb api
Web api
 
Reverse proxies & Inconsistency
Reverse proxies & InconsistencyReverse proxies & Inconsistency
Reverse proxies & Inconsistency
 
API for Beginners
API for BeginnersAPI for Beginners
API for Beginners
 
Rest API
Rest APIRest API
Rest API
 
Reverse Engineering iOS apps
Reverse Engineering iOS appsReverse Engineering iOS apps
Reverse Engineering iOS apps
 
Building Advanced XSS Vectors
Building Advanced XSS VectorsBuilding Advanced XSS Vectors
Building Advanced XSS Vectors
 
Talking About SSRF,CRLF
Talking About SSRF,CRLFTalking About SSRF,CRLF
Talking About SSRF,CRLF
 
HTML 5 & WebGL (Spanish Version)
HTML 5 & WebGL (Spanish Version)HTML 5 & WebGL (Spanish Version)
HTML 5 & WebGL (Spanish Version)
 
Rest web services
Rest web servicesRest web services
Rest web services
 
REST API Design & Development
REST API Design & DevelopmentREST API Design & Development
REST API Design & Development
 

Destaque

WP REST API - Adding Your Own Endpoint
WP REST API - Adding Your Own EndpointWP REST API - Adding Your Own Endpoint
WP REST API - Adding Your Own EndpointKeanan Koppenhaver
 
Are RESTful APIs Well-designed? Detection of their Linguistic (Anti)Patterns
Are RESTful APIs Well-designed? Detection of their Linguistic (Anti)PatternsAre RESTful APIs Well-designed? Detection of their Linguistic (Anti)Patterns
Are RESTful APIs Well-designed? Detection of their Linguistic (Anti)PatternsFrancis Palma
 
RESTful APIs: Promises & lies
RESTful APIs: Promises & liesRESTful APIs: Promises & lies
RESTful APIs: Promises & liesTareque Hossain
 
All you need to know when designing RESTful APIs
All you need to know when designing RESTful APIsAll you need to know when designing RESTful APIs
All you need to know when designing RESTful APIsJesús Espejo
 
How to deal with REST API Evolution
How to deal with REST API EvolutionHow to deal with REST API Evolution
How to deal with REST API EvolutionMiredot
 
API Design Essentials - Akana Platform Overview
API Design Essentials - Akana Platform OverviewAPI Design Essentials - Akana Platform Overview
API Design Essentials - Akana Platform OverviewAkana
 
Building a REST API for Longevity
Building a REST API for LongevityBuilding a REST API for Longevity
Building a REST API for LongevityMuleSoft
 
Deep-dive into Microservice Outer Architecture
Deep-dive into Microservice Outer ArchitectureDeep-dive into Microservice Outer Architecture
Deep-dive into Microservice Outer ArchitectureWSO2
 
Beautiful REST+JSON APIs with Ion
Beautiful REST+JSON APIs with IonBeautiful REST+JSON APIs with Ion
Beautiful REST+JSON APIs with IonStormpath
 
Building RESTful APIs
Building RESTful APIsBuilding RESTful APIs
Building RESTful APIsSilota Inc.
 
Building Beautiful REST APIs with ASP.NET Core
Building Beautiful REST APIs with ASP.NET CoreBuilding Beautiful REST APIs with ASP.NET Core
Building Beautiful REST APIs with ASP.NET CoreStormpath
 
Building Consistent RESTful APIs in a high-performance environment
Building Consistent RESTful APIs in a high-performance environmentBuilding Consistent RESTful APIs in a high-performance environment
Building Consistent RESTful APIs in a high-performance environmentLinkedIn
 
대용량 분산 아키텍쳐 설계 #1 아키텍쳐 설계 방법론
대용량 분산 아키텍쳐 설계 #1 아키텍쳐 설계 방법론대용량 분산 아키텍쳐 설계 #1 아키텍쳐 설계 방법론
대용량 분산 아키텍쳐 설계 #1 아키텍쳐 설계 방법론Terry Cho
 
From a monolith to microservices + REST: The evolution of LinkedIn's architec...
From a monolith to microservices + REST: The evolution of LinkedIn's architec...From a monolith to microservices + REST: The evolution of LinkedIn's architec...
From a monolith to microservices + REST: The evolution of LinkedIn's architec...Karan Parikh
 

Destaque (15)

RESTful API Design, Second Edition
RESTful API Design, Second EditionRESTful API Design, Second Edition
RESTful API Design, Second Edition
 
WP REST API - Adding Your Own Endpoint
WP REST API - Adding Your Own EndpointWP REST API - Adding Your Own Endpoint
WP REST API - Adding Your Own Endpoint
 
Are RESTful APIs Well-designed? Detection of their Linguistic (Anti)Patterns
Are RESTful APIs Well-designed? Detection of their Linguistic (Anti)PatternsAre RESTful APIs Well-designed? Detection of their Linguistic (Anti)Patterns
Are RESTful APIs Well-designed? Detection of their Linguistic (Anti)Patterns
 
RESTful APIs: Promises & lies
RESTful APIs: Promises & liesRESTful APIs: Promises & lies
RESTful APIs: Promises & lies
 
All you need to know when designing RESTful APIs
All you need to know when designing RESTful APIsAll you need to know when designing RESTful APIs
All you need to know when designing RESTful APIs
 
How to deal with REST API Evolution
How to deal with REST API EvolutionHow to deal with REST API Evolution
How to deal with REST API Evolution
 
API Design Essentials - Akana Platform Overview
API Design Essentials - Akana Platform OverviewAPI Design Essentials - Akana Platform Overview
API Design Essentials - Akana Platform Overview
 
Building a REST API for Longevity
Building a REST API for LongevityBuilding a REST API for Longevity
Building a REST API for Longevity
 
Deep-dive into Microservice Outer Architecture
Deep-dive into Microservice Outer ArchitectureDeep-dive into Microservice Outer Architecture
Deep-dive into Microservice Outer Architecture
 
Beautiful REST+JSON APIs with Ion
Beautiful REST+JSON APIs with IonBeautiful REST+JSON APIs with Ion
Beautiful REST+JSON APIs with Ion
 
Building RESTful APIs
Building RESTful APIsBuilding RESTful APIs
Building RESTful APIs
 
Building Beautiful REST APIs with ASP.NET Core
Building Beautiful REST APIs with ASP.NET CoreBuilding Beautiful REST APIs with ASP.NET Core
Building Beautiful REST APIs with ASP.NET Core
 
Building Consistent RESTful APIs in a high-performance environment
Building Consistent RESTful APIs in a high-performance environmentBuilding Consistent RESTful APIs in a high-performance environment
Building Consistent RESTful APIs in a high-performance environment
 
대용량 분산 아키텍쳐 설계 #1 아키텍쳐 설계 방법론
대용량 분산 아키텍쳐 설계 #1 아키텍쳐 설계 방법론대용량 분산 아키텍쳐 설계 #1 아키텍쳐 설계 방법론
대용량 분산 아키텍쳐 설계 #1 아키텍쳐 설계 방법론
 
From a monolith to microservices + REST: The evolution of LinkedIn's architec...
From a monolith to microservices + REST: The evolution of LinkedIn's architec...From a monolith to microservices + REST: The evolution of LinkedIn's architec...
From a monolith to microservices + REST: The evolution of LinkedIn's architec...
 

Semelhante a RESTFul API Design and Documentation - an Introduction

Introduction to RESTful API Designs
Introduction to RESTful API DesignsIntroduction to RESTful API Designs
Introduction to RESTful API DesignsRoman Kuba
 
Pragmatic RESTful API Design: Apigee Webinar
Pragmatic RESTful API Design: Apigee WebinarPragmatic RESTful API Design: Apigee Webinar
Pragmatic RESTful API Design: Apigee WebinarApigee | Google Cloud
 
Api development with rails
Api development with railsApi development with rails
Api development with railsEdwin Cruz
 
Pragmatic REST aka praxisnahes Schnittstellendesign
Pragmatic REST aka praxisnahes SchnittstellendesignPragmatic REST aka praxisnahes Schnittstellendesign
Pragmatic REST aka praxisnahes SchnittstellendesignOPEN KNOWLEDGE GmbH
 
Free The Enterprise With Ruby & Master Your Own Domain
Free The Enterprise With Ruby & Master Your Own DomainFree The Enterprise With Ruby & Master Your Own Domain
Free The Enterprise With Ruby & Master Your Own DomainKen Collins
 
APIdays Helsinki 2019 - API Versioning with REST, JSON and Swagger with Thoma...
APIdays Helsinki 2019 - API Versioning with REST, JSON and Swagger with Thoma...APIdays Helsinki 2019 - API Versioning with REST, JSON and Swagger with Thoma...
APIdays Helsinki 2019 - API Versioning with REST, JSON and Swagger with Thoma...apidays
 
Atlrug intermodal - sep 2011
Atlrug   intermodal - sep 2011Atlrug   intermodal - sep 2011
Atlrug intermodal - sep 2011hosheng
 
Building Awesome APIs in Grails
Building Awesome APIs in GrailsBuilding Awesome APIs in Grails
Building Awesome APIs in Grailsclatimer
 
Automate your automation with Rudder’s API! \o/
Automate your automation with Rudder’s API! \o/Automate your automation with Rudder’s API! \o/
Automate your automation with Rudder’s API! \o/RUDDER
 
Python tools for testing web services over HTTP
Python tools for testing web services over HTTPPython tools for testing web services over HTTP
Python tools for testing web services over HTTPMykhailo Kolesnyk
 
Rails Presentation (Anton Dmitriyev)
Rails Presentation (Anton Dmitriyev)Rails Presentation (Anton Dmitriyev)
Rails Presentation (Anton Dmitriyev)True-Vision
 
APIs REST Usables con Hypermedia por Javier Ramirez, para codemotion
APIs REST Usables con Hypermedia por Javier Ramirez, para codemotionAPIs REST Usables con Hypermedia por Javier Ramirez, para codemotion
APIs REST Usables con Hypermedia por Javier Ramirez, para codemotionjavier ramirez
 
Big Data Web applications for Interactive Hadoop by ENRICO BERTI at Big Data...
 Big Data Web applications for Interactive Hadoop by ENRICO BERTI at Big Data... Big Data Web applications for Interactive Hadoop by ENRICO BERTI at Big Data...
Big Data Web applications for Interactive Hadoop by ENRICO BERTI at Big Data...Big Data Spain
 
2012 12 best of spc - moving to the sp2013 app model
2012 12 best of spc - moving to the sp2013 app model2012 12 best of spc - moving to the sp2013 app model
2012 12 best of spc - moving to the sp2013 app modelbgerman
 

Semelhante a RESTFul API Design and Documentation - an Introduction (20)

Introduction to RESTful API Designs
Introduction to RESTful API DesignsIntroduction to RESTful API Designs
Introduction to RESTful API Designs
 
Pragmatic RESTful API Design: Apigee Webinar
Pragmatic RESTful API Design: Apigee WebinarPragmatic RESTful API Design: Apigee Webinar
Pragmatic RESTful API Design: Apigee Webinar
 
Api development with rails
Api development with railsApi development with rails
Api development with rails
 
Pragmatic REST aka praxisnahes Schnittstellendesign
Pragmatic REST aka praxisnahes SchnittstellendesignPragmatic REST aka praxisnahes Schnittstellendesign
Pragmatic REST aka praxisnahes Schnittstellendesign
 
Restful design at work v2.0
Restful design at work v2.0Restful design at work v2.0
Restful design at work v2.0
 
Free The Enterprise With Ruby & Master Your Own Domain
Free The Enterprise With Ruby & Master Your Own DomainFree The Enterprise With Ruby & Master Your Own Domain
Free The Enterprise With Ruby & Master Your Own Domain
 
APIdays Helsinki 2019 - API Versioning with REST, JSON and Swagger with Thoma...
APIdays Helsinki 2019 - API Versioning with REST, JSON and Swagger with Thoma...APIdays Helsinki 2019 - API Versioning with REST, JSON and Swagger with Thoma...
APIdays Helsinki 2019 - API Versioning with REST, JSON and Swagger with Thoma...
 
Don't screw it up! How to build durable API
Don't screw it up! How to build durable API Don't screw it up! How to build durable API
Don't screw it up! How to build durable API
 
Atlrug intermodal - sep 2011
Atlrug   intermodal - sep 2011Atlrug   intermodal - sep 2011
Atlrug intermodal - sep 2011
 
Building Awesome APIs in Grails
Building Awesome APIs in GrailsBuilding Awesome APIs in Grails
Building Awesome APIs in Grails
 
Automate your automation with Rudder’s API! \o/
Automate your automation with Rudder’s API! \o/Automate your automation with Rudder’s API! \o/
Automate your automation with Rudder’s API! \o/
 
Python tools for testing web services over HTTP
Python tools for testing web services over HTTPPython tools for testing web services over HTTP
Python tools for testing web services over HTTP
 
Rails 101
Rails 101Rails 101
Rails 101
 
Crafting APIs
Crafting APIsCrafting APIs
Crafting APIs
 
Rails Presentation (Anton Dmitriyev)
Rails Presentation (Anton Dmitriyev)Rails Presentation (Anton Dmitriyev)
Rails Presentation (Anton Dmitriyev)
 
APIs REST Usables con Hypermedia por Javier Ramirez, para codemotion
APIs REST Usables con Hypermedia por Javier Ramirez, para codemotionAPIs REST Usables con Hypermedia por Javier Ramirez, para codemotion
APIs REST Usables con Hypermedia por Javier Ramirez, para codemotion
 
Introduction to python scrapping
Introduction to python scrappingIntroduction to python scrapping
Introduction to python scrapping
 
Cqrs api v2
Cqrs api v2Cqrs api v2
Cqrs api v2
 
Big Data Web applications for Interactive Hadoop by ENRICO BERTI at Big Data...
 Big Data Web applications for Interactive Hadoop by ENRICO BERTI at Big Data... Big Data Web applications for Interactive Hadoop by ENRICO BERTI at Big Data...
Big Data Web applications for Interactive Hadoop by ENRICO BERTI at Big Data...
 
2012 12 best of spc - moving to the sp2013 app model
2012 12 best of spc - moving to the sp2013 app model2012 12 best of spc - moving to the sp2013 app model
2012 12 best of spc - moving to the sp2013 app model
 

Último

PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfLivetecs LLC
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
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.
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 

Último (20)

PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdf
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
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
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 

RESTFul API Design and Documentation - an Introduction

  • 1. miredotmiredot miredot RESTful API Design and Documentation – an Introduction BeJUG April 2016
  • 2. miredotmiredotmiredot Agenda REST – What and Why? Basic REST Design Principles Documenting a REST API Quick Demos Miredot POST https://api.twitter.com/tweets { “status”: “Great to be at BeJUG" } POST https://api.twitter.com/1.1/statuses/update.json?status=Great%20to%20be%at%BeJUG * **
  • 3. miredotmiredotmiredot REST – What and Why? REpresentational State Transfer Things/resources instead actions (SOAP/RPC) Using HTTP the right way Stateless (if possible) Cache-able, Firewall-able, Proxy-able (JSON) For purists: know the initial URI and navigate via hyperlinks (HATEAOS)
  • 5. miredotmiredotmiredot REST Design Principles Religiously RESTful vs REST-like Goals 1. Easy to use API 2. Predictable behavior 3. Works with existing infrastructure (proxies, browsers) Don’t think Java, think API first!
  • 6. miredotmiredotmiredot REST Design Principles – URI / Resource https://api.acme.com/petstore/dogs/5/toys/2/parts base URL all the dogs dog with id=5 toy with id=2 all the toys of dog 5 all the parts of toy 2 ?material=plastic Rule1: Plural for collections, ID for single element Rule2: No verbs! ../petstore/dogs/add Rule3: Query params only for meta-info (filtering, format) extra info
  • 7. miredotmiredotmiredot REST Design Principles – Operations Choose your operation wisely! POST /dogs/5/toys PUT /dogs/5/toys/2 GET /dogs/5 GET /dogs?fur=brown DELETE /dogs/5/toys/2 Give dog 5 a new toy Change something about his toy Get all data of dog 5 Get all dogs called Snoopy Take away his toy POST = Create PUT = Update (or create) GET = Read DELETE = Delete
  • 8. miredotmiredotmiredot REST Design Principles – Operations Choose your operation wisely! POST /dogs/5/toys PUT /dogs/5/toys/2 GET /dogs/5 GET /dogs?fur=brown DELETE /dogs/5/toys/2 Give dog 5 a new toy Change something about his toy Get all data of dog 5 Get all dogs called Snoopy Take away his toy 201 CREATED “2” { “name”: “chicken” } request response
  • 9. miredotmiredotmiredot REST Design Principles – Operations Choose your operation wisely! POST /dogs/5/toys PUT /dogs/5/toys/2 GET /dogs/5 GET /dogs?fur=brown DELETE /dogs/5/toys/2 Give dog 5 a new toy Change something about his toy Get all data of dog 5 Get all dogs called Snoopy Take away his toy 200 OK{ “name”: “duck” } request response
  • 10. miredotmiredotmiredot REST Design Principles – Operations Choose your operation wisely! POST /dogs/5/toys PUT /dogs/5/toys/2 GET /dogs/5 GET /dogs?fur=brown DELETE /dogs/5/toys/2 Give dog 5 a new toy Change something about his toy Get all data of dog 5 Get all dogs called Snoopy Take away his toy 200 OK { “name”: “Snoopy” “favouriteToy”: 2 } N/A request response
  • 11. miredotmiredotmiredot REST Design Principles – Operations Choose your operation wisely! POST /dogs/5/toys PUT /dogs/5/toys/2 GET /dogs/5 GET /dogs?fur=brown DELETE /dogs/5/toys/2 Give dog 5 a new toy Change something about his toy Get all data of dog 5 Get all dogs called Snoopy Take away his toy 200 OK [{ “name”: “Scooby Doo” }, { “name”: “Lassie” }] N/A request response
  • 12. miredotmiredotmiredot REST Design Principles – Operations Choose your operation wisely! POST /dogs/5/toys PUT /dogs/5/toys/2 GET /dogs/5 GET /dogs?fur=brown DELETE /dogs/5/toys/2 Give dog 5 a new toy Change something about his toy Get all data of dog 5 Get all dogs called Snoopy Take away his toy 200 NO CONTENTN/A request response
  • 13. miredotmiredotmiredot REST Design Principles – Operations Choose your operation wisely! POST /dogs/5/toys PUT /dogs/5/toys/2 GET /dogs/5 GET /dogs?fur=brown DELETE /dogs/5/toys/2 Rule1: GET is readonly, has no side effects (, cacheable) Rule2: POST creates, PUT creates or updates Rule3: GET/PUT/DELETE are idempotent Give dog 5 a new toy Change something about his toy Get all data of dog 5 Get all dogs called Snoopy Take away his toy
  • 14. miredotmiredotmiredot REST Design Principles See http://www.miredot.com/blog/posts/rest-api-design-basic-rules/
  • 16. miredotmiredotmiredot REST API Issues GET has a side-effect Never do this as this is often cached, pre-fetched, etc. Will cause hard to debug problems GET /accounts/3/balance à Wires €10 to Acme company GET /accounts/3/balance GET /accounts/3/balance GET /accounts/3/balance GET /accounts/3/balance à Wires €10 to Acme company à Wires €10 to Acme company …
  • 17. miredotmiredotmiredot REST API Issues Data in query parameters POST https://api.twitter.com/statuses/update?status=Great%20to%20be%at%BeJUG POST //api.twitter.com/statuses/ { “status”: “Great to be at BEJUG” } PUT //api.twitter.com/statuses/4 { “status” : “Great to be at BEJUG” } Client-generated ID
  • 18. miredotmiredotmiredot REST API Issues Verbs in the resource path Failed form of RPC /getAccount /createDirectory /group/update /dogs/4/bark GET PUT POST ?
  • 19. miredotmiredotmiredot REST API Issues How do I make a dog bark? POST /dogs/5/bark POST /dogs/5/commands/ { “command”: “bark” } GET /dogs/5/commands/1 { “id”: 1, “command”: “bark”, “status”: “executed”, “time”: “2016-04-19” } Optional Reify the action à commands
  • 20. miredotmiredotmiredot REST Design Principles – Other considerations Payloads (prefer JSON) Big vs small, field naming: be consistent (HATEOAS) Representation: one resource, multiple formats Accept and content-type headers Versioning Header, accept/content-type, URL Security Oauth, don’t invent your own
  • 22. miredotmiredotmiredot Take care of your API It’s the user interface of your service Be API-centric, not Java-centric! Design your API with the whole team Review your API regularly Be consistent above all
  • 24. miredotmiredotmiredot How Important is API Documentation? For private APIs: VERY I DON’T want to look at your source code For public APIs: Didn’t find a word to describe Developers will hate your API, you and your company.
  • 25. miredotmiredotmiredot Three Approaches Write it yourself Wikis, Word, Web-page Dedicated Wikis API Specification Language RAML, API Blueprint, Swagger Generate Miredot, Enunciate, Swagger, JsonDoc, APIDoc
  • 26. miredotmiredotmiredot Write yourself 1.  Word: DON’T 2.  Wiki: avoid 3.  readme.io, gelato.io: Nice docs, flexible REST/JSON-editor Import from Apiary, RAML, Swagger Hard to maintain Very hard to test (Never in sync with the implementation)
  • 28. miredotmiredotmiredot API Specification Language API First: focus on design RAML, SwaggerSpec, API Blueprint (Apiary) Cross-language, cross-framework Hard to maintain Test your API through the spec: hard
  • 29. miredotmiredotmiredot RAML Mulesoft, Anypoint platform YAML based, very modular Many tools, plugins: generate clients, documentation, parser, validator Varying quality API Specification Language Swagger (2.0) Smart Bear, Open API initiative Both a spec and tooling, also YAML Comes with core tooling (Swagger UI), several open source tools SwaggerUI: runtime component, interactive documentation More closely integration in your project (also Java)
  • 32. miredotmiredotmiredot Generators Get documentation for free Is my language / are my frameworks supported? Jax-rs, Spring-mvc / Jackson, Gson Is the output correct? Does it understand all my Java code (types, generics, frameworks)? Do I need to add anything to my code? Documentation always in sync with implementation Sit back and relax
  • 33. miredotmiredotmiredot Enunciate One of the first generators for Java Supported frameworks Jax-rs Outputs Website, client libraries, WSDL, WADL Swagger Supported frameworks Jax-rs (very limited), Spring-mvc (via SpringFox) Requires its own annotations Outputs Website, interactive api client, client libraries, server stubs
  • 34. miredotmiredotmiredot Miredot We were not satisfied with existing generators Don’t support all Java constructs (generics, inheritance, …) or frameworks Hard to setup (hours/days) Java Support Full Jax-rs, Spring-mvc, Jackson, RestEasy, Guava, … Generics, inheritance, Optionals, Guava, … Outputs Website (static), Word, RAML Documentation quality reporting
  • 36. miredotmiredotmiredot Miredot Free for open source, subscription for commercial projects Pay-per-endpoint Roadmap Documentation Quality Dashboard (Sonar-like) Version compatibility checking
  • 37. miredotmiredotmiredot Final Words 1.  Carefully design your API, you’ll be stuck with it for a long time 2.  Don’t let documentation be an afterthought: start from day one 3.  Use the many tools that are out there, they help a lot!