SlideShare a Scribd company logo
1 of 43
Download to read offline
There is REST and
then there is “REST”
Radovan SemanÄŤĂ­k
November 2017
Who Am I?
Ing. Radovan SemanÄŤĂ­k, PhD.
Software Architect at Evolveum
Architect of Evolveum midPoint
Apache Foundation committer
Contributor to ConnId and Apache Directory API
What is REST?
Server
JavaScript in browser
Mobile application
Enterprise application
CLI tool
Desktop client
…
Client HTTP
JSON
request
Web application
Enterprise application
“Cloud” application
Whatever as a Service
“Serverless” server
...
JSON
response
What is REST?
Server
JavaScript in browser
Mobile application
Enterprise application
CLI tool
Desktop client
…
Client HTTP
JSON
request
JSON
response
Web application
Enterprise application
“Cloud” application
Whatever as a Service
“Serverless” server
...
This is simple, easy to understand … and wrong
Who Are You?
I know
everything
about
REST
already
Whatever.
I do not need
to know REST
This may be interesting
Back to 1990s ...
â—Ź 1990: WWW invented
• Tim Berners-Lee
â—Ź 1996: HTTP 1.0
â—Ź 1997: HTTP 1.1
â—Ź 2000: Representational State Transfer
• Roy Fielding
â—Ź 2002: WWW Architecture
REpresentational State Transfer
REST (according to Fielding)
â—Ź Architectural style
• Not “architecture”, not “protocol”, not “API”
â—Ź Retro-architecture (HTTP 1.1)
â—Ź Transfer of resource representations
• HTML page is a representation, HTTP is transfer protocol
â—Ź Architectural constraints
• Client-server, Stateless, Cache, Uniform interface, Layered
system, Code on demand
Representational State Transfer
Source: Fielding R.: Architectural Styles and the Design of Network-based Software Architectures, 2000
So, what exactly is wrong?
ServerClient HTTP
JSON
request
JSON
response
JSON? Not really ...
ServerClient HTTP
request
response
Request-response … kind of ...
ServerClient HTTP
URL
resource
representation
Operations (verbs):
â—Ź GET
â—Ź PUT
â—Ź DELETE
â—Ź POST
â—Ź ...
REST is not RPC
â—Ź Objects (resources) addressed by URL
â—Ź Fixed operation set (verbs)
• GET, HEAD, PUT, DELETE, POST, OPTIONS, TRACE, CONNECT
â—Ź Stateless
• Sessions are evil
â—Ź Hypertext
• Thou shalt not construct your URLs
Theory and Practice
â—Ź Theory: REST is architectural style for
hypertext applications
â—Ź Practice: we really need RCP
â—Ź REST is not good for RPC
… but REST is popular, we want it …
â—Ź Result: RESTful APIs
RESTful APIs
â—Ź Not really REST
• Not hypertext
• Mostly resource-based, but still some RPC
â—Ź Not really API
• Application Programming Interface
• Problematic interface definition (Swagger/OpenAPI?)
• Security? Reliability? Transactions?
● Read: “HTTP-based service”
Reinvented Wheel … again
â—Ź 1976: RFC 707
â—Ź 1981: Xerox Courier
â—Ź 1991: CORBA
● 1993: DCE/RPC → DCOM
â—Ź 1995: SunRPC
â—Ź 1998: SOAP
● 200x: “RESTful” API
Pure REST
â—Ź It is possible to implement pure REST service
… but it is going to be real pain (very likely)
• Careful design and implementation
• Unnecessary complexity
• Too many network round-trips
• Expect poor performance
â—Ź Hypertext is not suitable for everything
What do we do?
â—Ź Keep the parts that fit
• Resources, URLs, representations
• GET, DELETE, POST, …
â—Ź Ditch the parts that do not fit
• Hypertext
â—Ź Compromises
• Statelessness, caching, security, consistency, ...
â—Ź Interface definition
• Swagger/OpenAPI
Practical “REST”
â—Ź Try to stick to resources and representations
• URL represents object (resource)
â—Ź GET as safe operation
â—Ź Use POST for RPC when needed
• But do not abuse
â—Ź Define the interface
• URL formats and meaning, data types, inputs/outputs, ...
Practical case study: midPoint
â—Ź MidPoint: comprehensive identity
management and governance system
• Identity management, provisioning, role-based access control,
audit, workflow, entitlement management, password management,
policy management, segregation of duties, …
â—Ź 100% open source
â—Ź Started in 2011
â—Ź 700k lines of (mostly) Java code
(things are a bit
complex in this part)
MidPoint Services
midPoint
Self-service
application
IDE
User
Developer
Custom
client
Enterprise
integration
Mobile
application
MidPoint “REST” service
â—Ź Development started in 2013
â—Ź Existing data model and operations
• Object-based: User, Role, Organizational unit, Account, Task,
Security policy, ...
• CRUD … but there are exceptions
● “RESTful” part and RPC part
â—Ź Kept as close to REST ideas as was practical
RESTful Operations: object
http://…./rest/users/02c15378­c48b­11e7­b010­1ff8606bae23
prefix type object identifier (OID)
Verbs:
â—Ź GET: read
â—Ź POST: modify
â—Ź DELETE: delete
â—Ź PUT: create (not recommended)
How does object look like?
<user oid="02c15378­c48b­11e7­b010­1ff8606bae23">
    <name>jack</name>
    <description>Where's the rum?</description>
    <fullName>Jack Sparrow</fullName>
    <givenName>Jack</givenName>
    <familyName>Sparrow</familyName>
    <emailAddress>jack.sparrow@evolveum.com</emailAddress>
    <locality>Caribbean</locality>
    <activation>
     <administrativeStatus>enabled</administrativeStatus>
    </activation>
</user>
{
    "name" : "jack",
    "fullName" : "Jack Sparrow",
    "givenName" : "Jack", 
    "familyName" : "Sparrow",
    …
XML
JSON
RESTful Operations: collection
http://…./rest/users
prefix type
Verbs:
â—Ź GET: list objects, search (theoretically)
â—Ź POST: create new object
â—Ź DELETE: not supported
â—Ź PUT: not supported
Search
â—Ź Query language
<q:equal>
    <q:path>name</q:path>
    <q:value>jack</q:value>
</q:equal>
â—Ź Search with POST: convenience
â—Ź Deviation from REST
• Dedicated “search” resource for POST instead of GET
• Should return list of URLs, but returns objects (to save round trips)
http://…./rest/users/search
HTTP verbs
â—Ź GET is safe
â—Ź POST used for many things
â—Ź DELETE deletes
â—Ź PUT is not very useful
â—Ź PATCH for modification
• But POST works as well
● Typical “REST” API
Error Codes
â—Ź 1xx: Information. Stay tuned.
â—Ź 2xx: Success. All done.
● 3xx: Redirection or “in progress” (we will get to that)
â—Ź 4xx: Client error (e.g. bad request)
â—Ź 5xx: Server error (e.g. bug in server code)
Trivial, isn’t it? Now let’s have a
look at the interesting stuff.
Asynchronous Operations
â—Ź Operations that take a looooong time (days)
â—Ź Cannot return success (2xx)
â—Ź Solution: redirects (3xx)
Asynchronous Operations
midPointclient
Modify user
POST …/users/12345
Redirect
302: …/tasks/87654
Start operation:
create new task
Task
87654
Check task
GET …/tasks/87654
200: <task>...</task>
RPC Operations: object-related
http://…/rest/tasks/c68d7770­c493­11e7­bce6­9bec1fc3b57c/suspend
prefix type object identifier (OID)
Verbs:
â—Ź GET: not applicable
â—Ź POST: execute the operation
â—Ź DELETE: not applicable
â—Ź PUT: not applicable
op
Object-related RPC operations
â—Ź Deviation from pure REST
• Should be modeled as resource changes or separate resources
… but that is a pain
â—Ź Error handling
RPC Operations: global
http://…/rest/notifyChange
prefix
Verbs:
â—Ź GET: not applicable
â—Ź POST: execute the operation
â—Ź DELETE: not applicable
â—Ź PUT: not applicable
operation
Global RPC operations
â—Ź Complex input and output data structures
â—Ź Huge deviation from pure REST
â—Ź It was necessary to keep the interface simple
and efficient
Next: really hard problems ...
Security
â—Ź REST is stateless
• Cookie-based sessions are out
â—Ź HTTP Basic authentication
• Oh, really?
â—Ź OAuth2 / OpenID Connect
• “best” practice for REST APIs
â—Ź JSON Web Tokens (JWT)
• SAML tokens reinvented
Interface Definition
â—Ź Swagger / OpenAPI
• WSDL reinvented (CORBA IDL reinvented)
• JSON-oriented
• Still quite limited, but at least something
â—Ź REST purists hate it
• Because this goes directly against hypertext principles
Stub and Skeleton
Client
app
t1.suspend()
Interface definition
stub
Server
suspend() {
  …
}
skeleton
HTTP
POST
generate
code
generate
code
Does not really works in “RESTful” APIs (yet)
Transactions and Consistency
â—Ź Transactions (ACID)
• Forget it
â—Ź Consistency
• Cannot forget it, but it is tricky
• Optimistic locking / MVCC is best bet
• ETag (RFC7232) is a standard mechanism
• But a lot of proprietary mechanisms is used instead
Conclusion
â—Ź REST is no good for RPC
… but we are going to use it anyway
â—Ź And it is practical
… with some tweaks and compromises
â—Ź Future?
Questions and Answers
Radovan SemanÄŤĂ­k
www.evolveum.com
Thank You

More Related Content

What's hot

Resume
ResumeResume
Resume
Mina k
 

What's hot (17)

OpenIDM - Flexible Provisioning Platform - April 28 Webinar
OpenIDM - Flexible Provisioning Platform - April 28 WebinarOpenIDM - Flexible Provisioning Platform - April 28 Webinar
OpenIDM - Flexible Provisioning Platform - April 28 Webinar
 
OpenID Foundation RISC WG Update - 2017-10-16
OpenID Foundation RISC WG Update - 2017-10-16OpenID Foundation RISC WG Update - 2017-10-16
OpenID Foundation RISC WG Update - 2017-10-16
 
Ekon20 mORMot Legacy Code Technical Debt Delphi Conference
Ekon20 mORMot Legacy Code Technical Debt Delphi Conference Ekon20 mORMot Legacy Code Technical Debt Delphi Conference
Ekon20 mORMot Legacy Code Technical Debt Delphi Conference
 
angular-wakanda ngParis meetup 15 at 42
angular-wakanda ngParis meetup 15 at 42angular-wakanda ngParis meetup 15 at 42
angular-wakanda ngParis meetup 15 at 42
 
Characerizing and Validating QoS in the Emerging IoT Network
Characerizing and Validating QoS in the Emerging IoT NetworkCharacerizing and Validating QoS in the Emerging IoT Network
Characerizing and Validating QoS in the Emerging IoT Network
 
Vs java (1)
Vs java (1)Vs java (1)
Vs java (1)
 
End-to-end HTML5 APIs - The Geek Gathering 2013
End-to-end HTML5 APIs - The Geek Gathering 2013End-to-end HTML5 APIs - The Geek Gathering 2013
End-to-end HTML5 APIs - The Geek Gathering 2013
 
OpenID Foundation Connect Working Group Update - October 22, 2018
OpenID Foundation Connect Working Group Update - October 22, 2018OpenID Foundation Connect Working Group Update - October 22, 2018
OpenID Foundation Connect Working Group Update - October 22, 2018
 
OpenID Foundation Workshop at EIC 2018 - OpenID Certification Update
OpenID Foundation Workshop at EIC 2018 - OpenID Certification UpdateOpenID Foundation Workshop at EIC 2018 - OpenID Certification Update
OpenID Foundation Workshop at EIC 2018 - OpenID Certification Update
 
OIDF Workshop at Verizon Media -- 9/30/2019 -- OpenID Connect Working Group U...
OIDF Workshop at Verizon Media -- 9/30/2019 -- OpenID Connect Working Group U...OIDF Workshop at Verizon Media -- 9/30/2019 -- OpenID Connect Working Group U...
OIDF Workshop at Verizon Media -- 9/30/2019 -- OpenID Connect Working Group U...
 
OIDF Workshop 4/29/2019 -- OpenID Certification Update
OIDF Workshop 4/29/2019 -- OpenID Certification UpdateOIDF Workshop 4/29/2019 -- OpenID Certification Update
OIDF Workshop 4/29/2019 -- OpenID Certification Update
 
ServerlessConf: Serverless for the Enterprise - Rafal Gancarz
ServerlessConf: Serverless for the Enterprise - Rafal GancarzServerlessConf: Serverless for the Enterprise - Rafal Gancarz
ServerlessConf: Serverless for the Enterprise - Rafal Gancarz
 
Front-end for Java developers Devoxx France 2018
Front-end for Java developers Devoxx France 2018Front-end for Java developers Devoxx France 2018
Front-end for Java developers Devoxx France 2018
 
Whitepages Practical Experience Converting from Ruby to Reactive
Whitepages Practical Experience Converting from Ruby to ReactiveWhitepages Practical Experience Converting from Ruby to Reactive
Whitepages Practical Experience Converting from Ruby to Reactive
 
OIDF Workshop at Verizon Media -- 9/30/2019 -- OpenID Certification Program U...
OIDF Workshop at Verizon Media -- 9/30/2019 -- OpenID Certification Program U...OIDF Workshop at Verizon Media -- 9/30/2019 -- OpenID Certification Program U...
OIDF Workshop at Verizon Media -- 9/30/2019 -- OpenID Certification Program U...
 
Resume
ResumeResume
Resume
 
OpenID Certification Program Update - 2018-04-02
OpenID Certification Program Update - 2018-04-02OpenID Certification Program Update - 2018-04-02
OpenID Certification Program Update - 2018-04-02
 

Similar to There is REST and then there is "REST"

JSON all the way
JSON all the wayJSON all the way
JSON all the way
Ronan Berder
 
Introduction to REST and Jersey
Introduction to REST and JerseyIntroduction to REST and Jersey
Introduction to REST and Jersey
Chris Winters
 
Applications of the REST Principle
Applications of the REST PrincipleApplications of the REST Principle
Applications of the REST Principle
elliando dias
 

Similar to There is REST and then there is "REST" (20)

RESTful applications: The why and how by Maikel Mardjan
RESTful applications: The why and how by Maikel MardjanRESTful applications: The why and how by Maikel Mardjan
RESTful applications: The why and how by Maikel Mardjan
 
JHipster Conf 2018 : Connect your JHipster apps to the world of APIs with Ope...
JHipster Conf 2018 : Connect your JHipster apps to the world of APIs with Ope...JHipster Conf 2018 : Connect your JHipster apps to the world of APIs with Ope...
JHipster Conf 2018 : Connect your JHipster apps to the world of APIs with Ope...
 
Creating a custom API for a headless Drupal
Creating a custom API for a headless DrupalCreating a custom API for a headless Drupal
Creating a custom API for a headless Drupal
 
GraphQL is actually rest
GraphQL is actually restGraphQL is actually rest
GraphQL is actually rest
 
Introduction to Backend Engineering
Introduction to Backend EngineeringIntroduction to Backend Engineering
Introduction to Backend Engineering
 
Angular (v2 and up) - Morning to understand - Linagora
Angular (v2 and up) - Morning to understand - LinagoraAngular (v2 and up) - Morning to understand - Linagora
Angular (v2 and up) - Morning to understand - Linagora
 
Switch to Backend 2023
Switch to Backend 2023Switch to Backend 2023
Switch to Backend 2023
 
Advanced Web Development in PHP - Understanding REST API
Advanced Web Development in PHP - Understanding REST APIAdvanced Web Development in PHP - Understanding REST API
Advanced Web Development in PHP - Understanding REST API
 
Simple Web Services with PHP
Simple Web Services with PHPSimple Web Services with PHP
Simple Web Services with PHP
 
APIs distribuidos con alta escalabilidad
APIs distribuidos con alta escalabilidadAPIs distribuidos con alta escalabilidad
APIs distribuidos con alta escalabilidad
 
SGCE 2015 REST APIs
SGCE 2015 REST APIsSGCE 2015 REST APIs
SGCE 2015 REST APIs
 
JSON all the way
JSON all the wayJSON all the way
JSON all the way
 
How To Maintain Million Lines Of Open Source Code And Remain Sane or The Stor...
How To Maintain Million Lines Of Open Source Code And Remain Sane or The Stor...How To Maintain Million Lines Of Open Source Code And Remain Sane or The Stor...
How To Maintain Million Lines Of Open Source Code And Remain Sane or The Stor...
 
RESTful with Drupal - in-s and out-s
RESTful with Drupal - in-s and out-sRESTful with Drupal - in-s and out-s
RESTful with Drupal - in-s and out-s
 
Introduction to REST and Jersey
Introduction to REST and JerseyIntroduction to REST and Jersey
Introduction to REST and Jersey
 
SOAP vs REST
SOAP vs RESTSOAP vs REST
SOAP vs REST
 
Applications of the REST Principle
Applications of the REST PrincipleApplications of the REST Principle
Applications of the REST Principle
 
Dust.js
Dust.jsDust.js
Dust.js
 
Nodejs
NodejsNodejs
Nodejs
 
ReST Vs SOA(P) ... Yawn
ReST Vs SOA(P) ... YawnReST Vs SOA(P) ... Yawn
ReST Vs SOA(P) ... Yawn
 

Recently uploaded

Recently uploaded (20)

WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
WSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid EnvironmentsWSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid Environments
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
WSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - KanchanaWSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - Kanchana
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...
WSO2Con2024 - Facilitating Broadband Switching Services for UK Telecoms Provi...
 
WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...
WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...
WSO2CON 2024 - Lessons from the Field: Legacy Platforms – It's Time to Let Go...
 
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and ApplicationsWSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
WSO2CON 2024 - Architecting AI in the Enterprise: APIs and Applications
 
WSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
WSO2CON2024 - Why Should You Consider Ballerina for Your Next IntegrationWSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
WSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
 
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public AdministrationWSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
WSO2CON 2024 - How CSI Piemonte Is Apifying the Public Administration
 
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
WSO2Con2024 - Simplified Integration: Unveiling the Latest Features in WSO2 L...
 

There is REST and then there is "REST"

  • 1. There is REST and then there is “REST” Radovan SemanÄŤĂ­k November 2017
  • 2. Who Am I? Ing. Radovan SemanÄŤĂ­k, PhD. Software Architect at Evolveum Architect of Evolveum midPoint Apache Foundation committer Contributor to ConnId and Apache Directory API
  • 3. What is REST? Server JavaScript in browser Mobile application Enterprise application CLI tool Desktop client … Client HTTP JSON request Web application Enterprise application “Cloud” application Whatever as a Service “Serverless” server ... JSON response
  • 4. What is REST? Server JavaScript in browser Mobile application Enterprise application CLI tool Desktop client … Client HTTP JSON request JSON response Web application Enterprise application “Cloud” application Whatever as a Service “Serverless” server ... This is simple, easy to understand … and wrong
  • 5. Who Are You? I know everything about REST already Whatever. I do not need to know REST This may be interesting
  • 6. Back to 1990s ... â—Ź 1990: WWW invented • Tim Berners-Lee â—Ź 1996: HTTP 1.0 â—Ź 1997: HTTP 1.1 â—Ź 2000: Representational State Transfer • Roy Fielding â—Ź 2002: WWW Architecture
  • 8. REST (according to Fielding) â—Ź Architectural style • Not “architecture”, not “protocol”, not “API” â—Ź Retro-architecture (HTTP 1.1) â—Ź Transfer of resource representations • HTML page is a representation, HTTP is transfer protocol â—Ź Architectural constraints • Client-server, Stateless, Cache, Uniform interface, Layered system, Code on demand
  • 9. Representational State Transfer Source: Fielding R.: Architectural Styles and the Design of Network-based Software Architectures, 2000
  • 10. So, what exactly is wrong? ServerClient HTTP JSON request JSON response
  • 11. JSON? Not really ... ServerClient HTTP request response
  • 12. Request-response … kind of ... ServerClient HTTP URL resource representation Operations (verbs): â—Ź GET â—Ź PUT â—Ź DELETE â—Ź POST â—Ź ...
  • 13. REST is not RPC â—Ź Objects (resources) addressed by URL â—Ź Fixed operation set (verbs) • GET, HEAD, PUT, DELETE, POST, OPTIONS, TRACE, CONNECT â—Ź Stateless • Sessions are evil â—Ź Hypertext • Thou shalt not construct your URLs
  • 14. Theory and Practice â—Ź Theory: REST is architectural style for hypertext applications â—Ź Practice: we really need RCP â—Ź REST is not good for RPC … but REST is popular, we want it … â—Ź Result: RESTful APIs
  • 15. RESTful APIs â—Ź Not really REST • Not hypertext • Mostly resource-based, but still some RPC â—Ź Not really API • Application Programming Interface • Problematic interface definition (Swagger/OpenAPI?) • Security? Reliability? Transactions? â—Ź Read: “HTTP-based service”
  • 16. Reinvented Wheel … again â—Ź 1976: RFC 707 â—Ź 1981: Xerox Courier â—Ź 1991: CORBA â—Ź 1993: DCE/RPC → DCOM â—Ź 1995: SunRPC â—Ź 1998: SOAP â—Ź 200x: “RESTful” API
  • 17. Pure REST â—Ź It is possible to implement pure REST service … but it is going to be real pain (very likely) • Careful design and implementation • Unnecessary complexity • Too many network round-trips • Expect poor performance â—Ź Hypertext is not suitable for everything
  • 18. What do we do? â—Ź Keep the parts that fit • Resources, URLs, representations • GET, DELETE, POST, … â—Ź Ditch the parts that do not fit • Hypertext â—Ź Compromises • Statelessness, caching, security, consistency, ... â—Ź Interface definition • Swagger/OpenAPI
  • 19. Practical “REST” â—Ź Try to stick to resources and representations • URL represents object (resource) â—Ź GET as safe operation â—Ź Use POST for RPC when needed • But do not abuse â—Ź Define the interface • URL formats and meaning, data types, inputs/outputs, ...
  • 20. Practical case study: midPoint â—Ź MidPoint: comprehensive identity management and governance system • Identity management, provisioning, role-based access control, audit, workflow, entitlement management, password management, policy management, segregation of duties, … â—Ź 100% open source â—Ź Started in 2011 â—Ź 700k lines of (mostly) Java code
  • 21. (things are a bit complex in this part) MidPoint Services midPoint Self-service application IDE User Developer Custom client Enterprise integration Mobile application
  • 22. MidPoint “REST” service â—Ź Development started in 2013 â—Ź Existing data model and operations • Object-based: User, Role, Organizational unit, Account, Task, Security policy, ... • CRUD … but there are exceptions â—Ź “RESTful” part and RPC part â—Ź Kept as close to REST ideas as was practical
  • 23. RESTful Operations: object http://…./rest/users/02c15378­c48b­11e7­b010­1ff8606bae23 prefix type object identifier (OID) Verbs: â—Ź GET: read â—Ź POST: modify â—Ź DELETE: delete â—Ź PUT: create (not recommended)
  • 24. How does object look like? <user oid="02c15378­c48b­11e7­b010­1ff8606bae23">     <name>jack</name>     <description>Where's the rum?</description>     <fullName>Jack Sparrow</fullName>     <givenName>Jack</givenName>     <familyName>Sparrow</familyName>     <emailAddress>jack.sparrow@evolveum.com</emailAddress>     <locality>Caribbean</locality>     <activation>      <administrativeStatus>enabled</administrativeStatus>     </activation> </user> {     "name" : "jack",     "fullName" : "Jack Sparrow",     "givenName" : "Jack",      "familyName" : "Sparrow",     … XML JSON
  • 25. RESTful Operations: collection http://…./rest/users prefix type Verbs: â—Ź GET: list objects, search (theoretically) â—Ź POST: create new object â—Ź DELETE: not supported â—Ź PUT: not supported
  • 26. Search â—Ź Query language <q:equal>     <q:path>name</q:path>     <q:value>jack</q:value> </q:equal> â—Ź Search with POST: convenience â—Ź Deviation from REST • Dedicated “search” resource for POST instead of GET • Should return list of URLs, but returns objects (to save round trips) http://…./rest/users/search
  • 27. HTTP verbs â—Ź GET is safe â—Ź POST used for many things â—Ź DELETE deletes â—Ź PUT is not very useful â—Ź PATCH for modification • But POST works as well â—Ź Typical “REST” API
  • 28. Error Codes â—Ź 1xx: Information. Stay tuned. â—Ź 2xx: Success. All done. â—Ź 3xx: Redirection or “in progress” (we will get to that) â—Ź 4xx: Client error (e.g. bad request) â—Ź 5xx: Server error (e.g. bug in server code)
  • 29. Trivial, isn’t it? Now let’s have a look at the interesting stuff.
  • 30. Asynchronous Operations â—Ź Operations that take a looooong time (days) â—Ź Cannot return success (2xx) â—Ź Solution: redirects (3xx)
  • 31. Asynchronous Operations midPointclient Modify user POST …/users/12345 Redirect 302: …/tasks/87654 Start operation: create new task Task 87654 Check task GET …/tasks/87654 200: <task>...</task>
  • 32. RPC Operations: object-related http://…/rest/tasks/c68d7770­c493­11e7­bce6­9bec1fc3b57c/suspend prefix type object identifier (OID) Verbs: â—Ź GET: not applicable â—Ź POST: execute the operation â—Ź DELETE: not applicable â—Ź PUT: not applicable op
  • 33. Object-related RPC operations â—Ź Deviation from pure REST • Should be modeled as resource changes or separate resources … but that is a pain â—Ź Error handling
  • 34. RPC Operations: global http://…/rest/notifyChange prefix Verbs: â—Ź GET: not applicable â—Ź POST: execute the operation â—Ź DELETE: not applicable â—Ź PUT: not applicable operation
  • 35. Global RPC operations â—Ź Complex input and output data structures â—Ź Huge deviation from pure REST â—Ź It was necessary to keep the interface simple and efficient
  • 36. Next: really hard problems ...
  • 37. Security â—Ź REST is stateless • Cookie-based sessions are out â—Ź HTTP Basic authentication • Oh, really? â—Ź OAuth2 / OpenID Connect • “best” practice for REST APIs â—Ź JSON Web Tokens (JWT) • SAML tokens reinvented
  • 38. Interface Definition â—Ź Swagger / OpenAPI • WSDL reinvented (CORBA IDL reinvented) • JSON-oriented • Still quite limited, but at least something â—Ź REST purists hate it • Because this goes directly against hypertext principles
  • 39. Stub and Skeleton Client app t1.suspend() Interface definition stub Server suspend() {   … } skeleton HTTP POST generate code generate code Does not really works in “RESTful” APIs (yet)
  • 40. Transactions and Consistency â—Ź Transactions (ACID) • Forget it â—Ź Consistency • Cannot forget it, but it is tricky • Optimistic locking / MVCC is best bet • ETag (RFC7232) is a standard mechanism • But a lot of proprietary mechanisms is used instead
  • 41. Conclusion â—Ź REST is no good for RPC … but we are going to use it anyway â—Ź And it is practical … with some tweaks and compromises â—Ź Future?