SlideShare a Scribd company logo
1 of 33
Download to read offline
Play! with REST
RESTful Web Services with Play!
About
● R&D Engineer at fluidOps
● Experiences with Play!
○ Version 1.4: Little custom made survey tool
○ Version 2.x: Distributed glossary at Capgemini
● Experiences with REST
○ Distributed Glossary exposed a REST interface
○ Played a little with Jersey (cf. JAX-RS)
http://github.com/gtrefs
This talk is about
● REST
○ What is REST?
○ What is a RESTful API?
○ Examples
● Play!
○ What is Play! ?
○ How do I built RESTful APIs with Play?
○ Example
REST
Representational State Transfer
Your experience?
● Experiences with REST
○ What is REST?
○ Who of you used REST?
Basic idea of REST
● Representational State Transfer
Network of web pages
(Application)
User User
Network of web pages
(Application)
Selects link
User
Network of web pages
(Application)
Representation of state
REST
● Term coined by Roy Fielding
● Architectural style
○ reflecting design decision and experiences while
adapting HTTP for the world wide web
○ constraints to emphasize specific properties
■ Client-Server → Scalability, Stateless (Session state kept
at client) → Scalability & Reliability, Uniform interface →
Independence of components, Use of Caching →
Efficiency, ...
The World Wide Web is
based on REST
REST APIs
APIs for the web
Richardson Maturity Model
● By Leonard Richardson
● 4 Levels of REST APIs
○ Level 0: HTTP as tunnel (cf. RPC)
○ Level 1: Resources
○ Level 2: HTTP verbs
○ Level 3: Hypermedia controls (aka HATEOAS)
Level 0 - HTTP as Transport Protocol
● Example: JSON-RPC
○ Relies on HTTP POST
○ Single service endpoint
http://blog.com/api
POST: {"jsonrpc": "2.0", "method": "create",
"params": ["Test", "message"], "id": 1}
200: {"jsonrpc": "2.0", "result": 0, "id": 1}
http://blog.com/api
POST: {"jsonrpc": "2.0", "method": "get",
"params": 0, "id": 2}
200: {"jsonrpc": "2.0", "result": ["Test",
"message"], "id": 2}
Level 1 - Resources
● Things which are addressable on their own
○ Entry collection: http://blog.com/api/entries
○ Single entry: http://blog.com/api/entries/{id}
http://blog.com/api/entries
POST: {"title":”Test”, "message":"message"}
200: {"id": 0}
http://blog.com/api/entries/0
POST
:
200: {"title":”Test”, "message":"message", "id":
0}
Level 2 - HTTP Verbs
http://blog.com/api/entries
POST: {"title":”Test”, "message":"message"}
201: Location: /api/entries/0
http://blog.com/api/entries/0
GET
200: {"title":”Test”, "message":"message", "id":
0}
● Exploit available semantics
○ GET: Retrieve information
○ DELETE: Remove resource
○ POST: New subordinate resource
○ PUT: Update or create resource
Level 3 - Hypermedia Controls
http://blog.com/api/entries
POST: {"title":”Test”, "message":"message"}
201: ... {"link":{"href": "/api/entries/0", "rel":"
item"}...}
http://blog.com/api/entries/0
GET
200: {"link":{"href":"/api/entries/0", "rel":"self"},
"link":{"href":"/api/entries", "rel":"collection"},
"title":”Test”, "message":"message", "id":0}
● Returned Hypermedia tells the client about
its interaction capabilities
○ Typed interlinking of resources (cf. Atom pub types)
Play! Web Framework
Based on Web MVC for Java and Scala
Your experience?
● Who knows what a Web Framework is?
● Who of you used a Web Framework?
○ RoR, Grails, Spring MVC, Zend or even Play!?
Basic workflow of Play!
routes
Client
HTTP Request
Controller/Action
Match
GET /api/entries
controller.Entries.list
HTTP Request
Model
models.Entry
View
views.html.Entry.list
Netty
SBT
JVM JacksonJPA
eBeanJava
Scala
Bean
Validation
Web
Sockets
Comet
Sockets
Akka
Twirl
JUnit
Mockito
Play!
● 2009: Released by Guillaume Bort
● Built on Akka
○ Part of the reactive Typesafe stack
○ Asynchronous and Non-blocking I/O
● Developer friendly
○ Does not hide HTTP
○ Web MVC
○ Everything is compiled
The Blog API
Play with entries
Building the Blog API
Resource Route Method Action
entries /blog/entries GET Retrieve all entries in the entries
collection
entries /blog/entries POST Create new entry from the payload
as item of the entries collection
entry /blog/entries/{id} GET Retrieve single entry for given id
entry /blog/entries/{id} PUT Update entry identified by given id
with information contained in the
payload
entry /blog/entries/{id} DELETE Delete entry from entries collection
The routes file
● Maps from request paths to actions
○ Path components can be declared as action
parameters
The Entries controller
● Logical container for all actions related to
entries
○ An action is a function which maps a request to a
response
○ Implementation of the Blog API
Get all entries action
● Retrieves all entries in the database
○ Uses JsonLinker to map entries to JSON
Create new entry action
● Creates new entry from HTTP body
○ Uses JSON BodyParser
○ Uses JsonLinker to return new entity as JSON
Get single entry action
● Retrieves a single entry for given id
○ Uses JsonLinker to map entry to JSON
Update single entry action
● Update single entry identified by given id
○ Uses JSON BodyParser
Delete single entry action
● Delete single entry identified by given id
Action composition
Code composition for Exception Handling, Authentication, …
Exception Handling
Calls Exception Result
Action composition
● In Play Scala actions are case classes
○ can be used in a functional style
○ wrap around other actions
● In Play Java: Annotation creep
Thank you! Questions?
REST Resources
● Richardson Marturity Model http://martinfowler.
com/articles/richardsonMaturityModel.html
● Discussion about the govdata.de API http://olivergierke.
de/2013/02/websites-vs-apis/
● Refactoring the govdata.de API https://speakerdeck.
com/owolf/turning-passive-apis-into-active-apis
● HAL https://tools.ietf.org/html/draft-kelly-json-hal-06
Play Resources
● Web Page https://www.playframework.com/
● GitHub https://github.
com/playframework/playframework

More Related Content

What's hot

C++ Windows Forms L07 - Collections
C++ Windows Forms L07 - CollectionsC++ Windows Forms L07 - Collections
C++ Windows Forms L07 - CollectionsMohammad Shaker
 
TypeScript and SharePoint Framework
TypeScript and SharePoint FrameworkTypeScript and SharePoint Framework
TypeScript and SharePoint FrameworkRyan Schouten
 
Build your first MongoDB App in Ruby @ StrangeLoop 2013
Build your first MongoDB App in Ruby @ StrangeLoop 2013Build your first MongoDB App in Ruby @ StrangeLoop 2013
Build your first MongoDB App in Ruby @ StrangeLoop 2013Steven Francia
 
Future-proof Development for Classic SharePoint
Future-proof Development for Classic SharePointFuture-proof Development for Classic SharePoint
Future-proof Development for Classic SharePointBob German
 
Autocomplete in elasticsearch
Autocomplete in elasticsearchAutocomplete in elasticsearch
Autocomplete in elasticsearchTaimur Qureshi
 
XPath for web scraping
XPath for web scrapingXPath for web scraping
XPath for web scrapingScrapinghub
 
Locomotor: transparent migration of client-side database code
Locomotor: transparent migration of client-side database codeLocomotor: transparent migration of client-side database code
Locomotor: transparent migration of client-side database codeMichael Mior
 
OpenOffice Application with Python
OpenOffice Application with PythonOpenOffice Application with Python
OpenOffice Application with Pythonimacat .
 

What's hot (12)

C++ Windows Forms L07 - Collections
C++ Windows Forms L07 - CollectionsC++ Windows Forms L07 - Collections
C++ Windows Forms L07 - Collections
 
TypeScript and SharePoint Framework
TypeScript and SharePoint FrameworkTypeScript and SharePoint Framework
TypeScript and SharePoint Framework
 
Build your first MongoDB App in Ruby @ StrangeLoop 2013
Build your first MongoDB App in Ruby @ StrangeLoop 2013Build your first MongoDB App in Ruby @ StrangeLoop 2013
Build your first MongoDB App in Ruby @ StrangeLoop 2013
 
Future-proof Development for Classic SharePoint
Future-proof Development for Classic SharePointFuture-proof Development for Classic SharePoint
Future-proof Development for Classic SharePoint
 
Scrapy.for.dummies
Scrapy.for.dummiesScrapy.for.dummies
Scrapy.for.dummies
 
Autocomplete in elasticsearch
Autocomplete in elasticsearchAutocomplete in elasticsearch
Autocomplete in elasticsearch
 
XPath for web scraping
XPath for web scrapingXPath for web scraping
XPath for web scraping
 
Graph ql api gateway
Graph ql api gatewayGraph ql api gateway
Graph ql api gateway
 
VB Dot net
VB Dot net VB Dot net
VB Dot net
 
Locomotor: transparent migration of client-side database code
Locomotor: transparent migration of client-side database codeLocomotor: transparent migration of client-side database code
Locomotor: transparent migration of client-side database code
 
Json
JsonJson
Json
 
OpenOffice Application with Python
OpenOffice Application with PythonOpenOffice Application with Python
OpenOffice Application with Python
 

Similar to Play! with RESTful Web Services

GraphQL in an Age of REST
GraphQL in an Age of RESTGraphQL in an Age of REST
GraphQL in an Age of RESTYos Riady
 
Enforcing API Design Rules for High Quality Code Generation
Enforcing API Design Rules for High Quality Code GenerationEnforcing API Design Rules for High Quality Code Generation
Enforcing API Design Rules for High Quality Code GenerationTim Burks
 
Extensible web #html5j
Extensible web #html5jExtensible web #html5j
Extensible web #html5jJxck Jxck
 
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
 
Dev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDBDev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDBMongoDB
 
Gutenberg Extended
Gutenberg ExtendedGutenberg Extended
Gutenberg ExtendedSören Wrede
 
Django REST Framework 2022fffffffff.pptx
Django REST Framework 2022fffffffff.pptxDjango REST Framework 2022fffffffff.pptx
Django REST Framework 2022fffffffff.pptxThirzaAhmadTsaqif
 
Web App Prototypes with Google App Engine
Web App Prototypes with Google App EngineWeb App Prototypes with Google App Engine
Web App Prototypes with Google App EngineVlad Filippov
 
Design Web Service API by HungerStation
Design Web Service API by HungerStationDesign Web Service API by HungerStation
Design Web Service API by HungerStationArabNet ME
 
Using the new WordPress REST API
Using the new WordPress REST APIUsing the new WordPress REST API
Using the new WordPress REST APICaldera Labs
 
Exploring Google (Cloud) APIs with Python & JavaScript
Exploring Google (Cloud) APIs with Python & JavaScriptExploring Google (Cloud) APIs with Python & JavaScript
Exploring Google (Cloud) APIs with Python & JavaScriptwesley chun
 
Build Great Networked APIs with Swift, OpenAPI, and gRPC
Build Great Networked APIs with Swift, OpenAPI, and gRPCBuild Great Networked APIs with Swift, OpenAPI, and gRPC
Build Great Networked APIs with Swift, OpenAPI, and gRPCTim Burks
 
Load testing in Zonky with Gatling
Load testing in Zonky with GatlingLoad testing in Zonky with Gatling
Load testing in Zonky with GatlingPetr Vlček
 
Google Devfest Singapore - OpenSocial
Google Devfest Singapore - OpenSocialGoogle Devfest Singapore - OpenSocial
Google Devfest Singapore - OpenSocialPatrick Chanezon
 
Generating Unified APIs with Protocol Buffers and gRPC
Generating Unified APIs with Protocol Buffers and gRPCGenerating Unified APIs with Protocol Buffers and gRPC
Generating Unified APIs with Protocol Buffers and gRPCC4Media
 

Similar to Play! with RESTful Web Services (20)

GraphQL in an Age of REST
GraphQL in an Age of RESTGraphQL in an Age of REST
GraphQL in an Age of REST
 
Enforcing API Design Rules for High Quality Code Generation
Enforcing API Design Rules for High Quality Code GenerationEnforcing API Design Rules for High Quality Code Generation
Enforcing API Design Rules for High Quality Code Generation
 
Extensible web #html5j
Extensible web #html5jExtensible web #html5j
Extensible web #html5j
 
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
 
Dev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDBDev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDB
 
Sprint 69
Sprint 69Sprint 69
Sprint 69
 
Gutenberg Extended
Gutenberg ExtendedGutenberg Extended
Gutenberg Extended
 
Django REST Framework 2022fffffffff.pptx
Django REST Framework 2022fffffffff.pptxDjango REST Framework 2022fffffffff.pptx
Django REST Framework 2022fffffffff.pptx
 
Web App Prototypes with Google App Engine
Web App Prototypes with Google App EngineWeb App Prototypes with Google App Engine
Web App Prototypes with Google App Engine
 
KSP intro
KSP introKSP intro
KSP intro
 
Design Web Service API by HungerStation
Design Web Service API by HungerStationDesign Web Service API by HungerStation
Design Web Service API by HungerStation
 
JSON API Specificiation
JSON API SpecificiationJSON API Specificiation
JSON API Specificiation
 
Go react codelab
Go react codelabGo react codelab
Go react codelab
 
Using the new WordPress REST API
Using the new WordPress REST APIUsing the new WordPress REST API
Using the new WordPress REST API
 
Exploring Google (Cloud) APIs with Python & JavaScript
Exploring Google (Cloud) APIs with Python & JavaScriptExploring Google (Cloud) APIs with Python & JavaScript
Exploring Google (Cloud) APIs with Python & JavaScript
 
Jenkins api
Jenkins apiJenkins api
Jenkins api
 
Build Great Networked APIs with Swift, OpenAPI, and gRPC
Build Great Networked APIs with Swift, OpenAPI, and gRPCBuild Great Networked APIs with Swift, OpenAPI, and gRPC
Build Great Networked APIs with Swift, OpenAPI, and gRPC
 
Load testing in Zonky with Gatling
Load testing in Zonky with GatlingLoad testing in Zonky with Gatling
Load testing in Zonky with Gatling
 
Google Devfest Singapore - OpenSocial
Google Devfest Singapore - OpenSocialGoogle Devfest Singapore - OpenSocial
Google Devfest Singapore - OpenSocial
 
Generating Unified APIs with Protocol Buffers and gRPC
Generating Unified APIs with Protocol Buffers and gRPCGenerating Unified APIs with Protocol Buffers and gRPC
Generating Unified APIs with Protocol Buffers and gRPC
 

Recently uploaded

(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
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
 
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
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
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
 
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
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
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
 
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
 
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
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 

Recently uploaded (20)

(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
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...
 
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
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
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...
 
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)
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
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...
 
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
 
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
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
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...
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 

Play! with RESTful Web Services

  • 1. Play! with REST RESTful Web Services with Play!
  • 2. About ● R&D Engineer at fluidOps ● Experiences with Play! ○ Version 1.4: Little custom made survey tool ○ Version 2.x: Distributed glossary at Capgemini ● Experiences with REST ○ Distributed Glossary exposed a REST interface ○ Played a little with Jersey (cf. JAX-RS) http://github.com/gtrefs
  • 3. This talk is about ● REST ○ What is REST? ○ What is a RESTful API? ○ Examples ● Play! ○ What is Play! ? ○ How do I built RESTful APIs with Play? ○ Example
  • 5. Your experience? ● Experiences with REST ○ What is REST? ○ Who of you used REST?
  • 6. Basic idea of REST ● Representational State Transfer Network of web pages (Application) User User Network of web pages (Application) Selects link User Network of web pages (Application) Representation of state
  • 7. REST ● Term coined by Roy Fielding ● Architectural style ○ reflecting design decision and experiences while adapting HTTP for the world wide web ○ constraints to emphasize specific properties ■ Client-Server → Scalability, Stateless (Session state kept at client) → Scalability & Reliability, Uniform interface → Independence of components, Use of Caching → Efficiency, ...
  • 8. The World Wide Web is based on REST
  • 10. Richardson Maturity Model ● By Leonard Richardson ● 4 Levels of REST APIs ○ Level 0: HTTP as tunnel (cf. RPC) ○ Level 1: Resources ○ Level 2: HTTP verbs ○ Level 3: Hypermedia controls (aka HATEOAS)
  • 11. Level 0 - HTTP as Transport Protocol ● Example: JSON-RPC ○ Relies on HTTP POST ○ Single service endpoint http://blog.com/api POST: {"jsonrpc": "2.0", "method": "create", "params": ["Test", "message"], "id": 1} 200: {"jsonrpc": "2.0", "result": 0, "id": 1} http://blog.com/api POST: {"jsonrpc": "2.0", "method": "get", "params": 0, "id": 2} 200: {"jsonrpc": "2.0", "result": ["Test", "message"], "id": 2}
  • 12. Level 1 - Resources ● Things which are addressable on their own ○ Entry collection: http://blog.com/api/entries ○ Single entry: http://blog.com/api/entries/{id} http://blog.com/api/entries POST: {"title":”Test”, "message":"message"} 200: {"id": 0} http://blog.com/api/entries/0 POST : 200: {"title":”Test”, "message":"message", "id": 0}
  • 13. Level 2 - HTTP Verbs http://blog.com/api/entries POST: {"title":”Test”, "message":"message"} 201: Location: /api/entries/0 http://blog.com/api/entries/0 GET 200: {"title":”Test”, "message":"message", "id": 0} ● Exploit available semantics ○ GET: Retrieve information ○ DELETE: Remove resource ○ POST: New subordinate resource ○ PUT: Update or create resource
  • 14. Level 3 - Hypermedia Controls http://blog.com/api/entries POST: {"title":”Test”, "message":"message"} 201: ... {"link":{"href": "/api/entries/0", "rel":" item"}...} http://blog.com/api/entries/0 GET 200: {"link":{"href":"/api/entries/0", "rel":"self"}, "link":{"href":"/api/entries", "rel":"collection"}, "title":”Test”, "message":"message", "id":0} ● Returned Hypermedia tells the client about its interaction capabilities ○ Typed interlinking of resources (cf. Atom pub types)
  • 15. Play! Web Framework Based on Web MVC for Java and Scala
  • 16. Your experience? ● Who knows what a Web Framework is? ● Who of you used a Web Framework? ○ RoR, Grails, Spring MVC, Zend or even Play!?
  • 17. Basic workflow of Play! routes Client HTTP Request Controller/Action Match GET /api/entries controller.Entries.list HTTP Request Model models.Entry View views.html.Entry.list Netty SBT JVM JacksonJPA eBeanJava Scala Bean Validation Web Sockets Comet Sockets Akka Twirl JUnit Mockito
  • 18. Play! ● 2009: Released by Guillaume Bort ● Built on Akka ○ Part of the reactive Typesafe stack ○ Asynchronous and Non-blocking I/O ● Developer friendly ○ Does not hide HTTP ○ Web MVC ○ Everything is compiled
  • 19. The Blog API Play with entries
  • 20. Building the Blog API Resource Route Method Action entries /blog/entries GET Retrieve all entries in the entries collection entries /blog/entries POST Create new entry from the payload as item of the entries collection entry /blog/entries/{id} GET Retrieve single entry for given id entry /blog/entries/{id} PUT Update entry identified by given id with information contained in the payload entry /blog/entries/{id} DELETE Delete entry from entries collection
  • 21. The routes file ● Maps from request paths to actions ○ Path components can be declared as action parameters
  • 22. The Entries controller ● Logical container for all actions related to entries ○ An action is a function which maps a request to a response ○ Implementation of the Blog API
  • 23. Get all entries action ● Retrieves all entries in the database ○ Uses JsonLinker to map entries to JSON
  • 24. Create new entry action ● Creates new entry from HTTP body ○ Uses JSON BodyParser ○ Uses JsonLinker to return new entity as JSON
  • 25. Get single entry action ● Retrieves a single entry for given id ○ Uses JsonLinker to map entry to JSON
  • 26. Update single entry action ● Update single entry identified by given id ○ Uses JSON BodyParser
  • 27. Delete single entry action ● Delete single entry identified by given id
  • 28. Action composition Code composition for Exception Handling, Authentication, …
  • 30. Action composition ● In Play Scala actions are case classes ○ can be used in a functional style ○ wrap around other actions ● In Play Java: Annotation creep
  • 32. REST Resources ● Richardson Marturity Model http://martinfowler. com/articles/richardsonMaturityModel.html ● Discussion about the govdata.de API http://olivergierke. de/2013/02/websites-vs-apis/ ● Refactoring the govdata.de API https://speakerdeck. com/owolf/turning-passive-apis-into-active-apis ● HAL https://tools.ietf.org/html/draft-kelly-json-hal-06
  • 33. Play Resources ● Web Page https://www.playframework.com/ ● GitHub https://github. com/playframework/playframework