SlideShare una empresa de Scribd logo
1 de 26
REST on steroids
    By Andrei Nefyodov
Representational State Transfer(REST) — set of architectural constraints

Constraint                Promotes                           At the expense of

Client-server             ●UI portability
                          ●Simplified server

                          ●Multiple organizational domains




Stateless                 ●Simplifiied server                Efficiency
                                                             ●

                          ●Scalability

                          ●Reliability


Optional non-shared       ●Reduced latency                   Reliability
                                                             ●

caching                   ●Efficiency

                          ●Scalability


Uniform interface         ●Visibility                        Efficiency
                                                             ●

                          ●Independent evolution

                          ●Decoupled implementation


Layered system            ●Shared caching                    Higher latency
                                                             ●

                          ●Legacy encapsulation

                          ●Simplified clients

                          ●Scalability

                          ●Load balancing


Optional code-on-demand   ●Simplified clients                Visibility
                                                             ●

                          ●Extensibility
Representational State Transfer(REST) — set of architectural constraints

Constraint                Promotes                            At the expense of
                                     Sub-constraints:
Client-server             ●UI portability
                                     ● Identification of resources
                          ●Simplified server
                                     ● Manipulation via representations
                          ●Multiple organizational domains
                                     ● Self-descriptive messages

                                     ●  Hypemedia as the engine of application state
Stateless                 ●Simplifiied server                 ●Efficiency

                          ●Scalability

                          ●Reliability


Optional non-shared       ●Reduced latency                    ●Reliability
caching                   ●Efficiency

                          ●Scalability


Uniform interface         ●Visibility                         ●Efficiency
                          ●Independent evolution

                          ●Decoupled implementation


Layered system            ●Shared caching                     ●Higher latency
                          ●Legacy encapsulation

                          ●Simplified clients

                          ●Scalability

                          ●Load balancing


Optional code-on-demand   ●Simplified clients                 ●Visibility
                          ●Extensibility
Representational State Transfer(REST) — set of architectural constraints

Constraint                Promotes                            At the expense of
                                     Sub-constraints:
Client-server             ●UI portability
                                     ● Identification of resources
                          ●Simplified server
                                     ● Manipulation via representations
                          ●Multiple organizational domains
                                     ● Self-descriptive messages

                                     ●  Hypemedia as the engine of application state
Stateless                 ●Simplifiied server                 ●Efficiency

                          ●Scalability

                          ●Reliability


Optional non-shared       ●Reduced latency                    ●Reliability
caching                   ●Efficiency

                          ●Scalability


Uniform interface         ●Visibility                         ●Efficiency

                          ●Independent evolution

                          ●Decoupled implementation You get these if
Layered system            ●Shared caching
                                                     you use HTTP latency
                                                              ●Higher

                          ●Legacy encapsulation
                                               as your application protocol
                          ●Simplified clients
                          ●Scalability

                          ●Load balancing


Optional code-on-demand   ●Simplified clients                 ●Visibility
                          ●Extensibility
Representational State Transfer(REST) — set of architectural constraints

Constraint                Promotes                            At the expense of
                                     Sub-constraints:
Client-server             ●UI portability
                                     ● Identification of resources
                          ●Simplified server
                                     ● Manipulation via representations
                          ●Multiple organizational domains
                                     ● Self-descriptive messages

                                     ●  Hypemedia as the engine of application state
Stateless                 ●Simplifiied server                 ●Efficiency

                          ●Scalability

                          ●Reliability


Optional non-shared       ●Reduced latency                    ●Reliability
caching                   ●Efficiency

                          ●Scalability


Uniform interface         ●Visibility                         ●Efficiency
                          ●Independent evolution

                          ●Decoupled implementation


Layered system            ●Shared caching                     ●Higher latency
                          ●Legacy encapsulation

                          ●Simplified clients

                          ●Scalability

                          ●Load balancing


Optional code-on-demand   ●Simplified clients                 ●Visibility
                          ●Extensibility
Hypermedia
●   Links in representations
●   State navigations discoverable
    HATEOAS — hypertext as the engine of
    application state. We express allowed state
    transitions through links.
●   Hypermedia constraint is an often-overlooked
    part of being RESTful
●   Using Hypermedia aware media type such as
    collection+json, XHTML promotes
➢   Loose coupling between client and server
➢   Simple documentation of semantic concepts
➢   Discoverability / testability / operability via
    «API surfing»
●   Much of the client framework is reusable
●   RESTBucks
●   Starbucks (like) coffee ordering
●   Order/payment
                                    5           6
                        Preparing       Ready       Completed

                    4
     2

1
         Payment
         expected


                         3


                        Cancelled
Method      URI                      Action              Step


POST        /orders                  Create new order    1


PUT/PATCH   /orders/4711             Update the order    2
                                     (only if «payment
                                     expected»)

DELETE      /orders/4711             Cancel order        3
                                     (only if «payment
                                     expected»)

PUT         /orders/4711/payment Pay order               4


                      Barista preparing the order


GET         /orders/4711             Poll order state    5


GET         /orders/4711/receipt     Access reciept


DELETE      /orders/4711/receipt     Conclude the        6
                                     order process
Challenges
How to avoid hard coding URIs?
Use link relations
Orders    Returns all orders available in the system

Order     Returns a single order

Self      The uri value can be used to GET the latest resource representation
          of the order.


Cancel    This is the URI to be used to DELETE the order resource should the
          consumer wish to cancel the order.


Update    Consumers can change the order using a POST to transfer a
          representation to the linked resource.


Payment   The linked resource allows the consumer to begin paying for an
          order. Initiating payment involves PUTting an appropriate resource
          representation to the specified URI.




Receipt   The URI to access the receipt using GET and conclude the order by
          taking the receipt (use DELETE).
Method      Relation type            Action              Step


POST        orders                   Create new order    1


PUT/PATCH   update                   Update the order    2
                                     (only if «payment
                                     expected»)

DELETE      cancel                   Cancel order        3
                                     (only if «payment
                                     expected»)

PUT         payment                  Pay order           4


                      Barista preparing the order


GET         order                    Poll order state    5


GET         receipt                  Access reciept


DELETE      receipt                  Conclude the        6
                                     order process
Challenges
How to implement «only if payment
expected»?
We can only navigate a link once it was
returned by the server
Place order
●   Access root resource
    { links : [ { rel : "orders",
                         href : "…/orders" }]
    }


●   Follow orders link
    $.links[?(@.rel="orders")].href
●   POST /orders
{
    links : [{
                 rel : "self",
                 href : "…/orders/4711"
                 },
        …
        …
                 {
                 rel : "payment",
                 href : "…/orders/4711/payment"
                 }    ],
    content : {
            items : [{
                      drink : "Cappucino",
                      size : "large",
                      milk : "semi"
                      price : 4.2
                 }
            ],
            location : "take-away",
            price : 4.2
            status : "payment expected"
    }
}
Trigger payment
●   Follow payment link
●   $.links[?(@.rel="payment")].href
●   PUT /orders/4711/payment
{
    links : [{
              rel : "self",
              href : "…/orders/4711/payment"
         }, {
              rel : "order",
              href : "…/orders/4711"
         }
    ],
    content : {
         creditCard : [{
                  number : "1234123412341234",
                  cardHolder : "Ivan Ivanov",
                  expiryDate : "2013-11-01"
              }
         ],
         amount : {
              currency : "EUR",
              value : 4.2
         }
    }
}
Poll order
●   Follow order link
    $.links[?(@.rel="order")].href
●   GET /orders/4711
●   ETag / If-None-Match
{
    links : [{
              rel : "self",
              href : "…/orders/4711"
         }
    ],
    content : {
         items : [{
                  drink : "Cappucino",
                  size : "large",
                  milk : "semi"
                  price : 4.2
              }
         ],
         location : "take-away",
         price : 4.2
         status : "preparing"
    }
}
{
    links : [{
              rel : "self",
              href : "…/orders/4711"
         }, {
              rel : "receipt",
              href : "…/orders/4711/receipt"
         }
    ],
    content : {
         items : [{
                  drink : "Cappucino",
                  size : "large",
                  milk : "semi"
                  price : 4.2
              }
         ],
         location : "take-away",
         price : 4.2
         status : "ready"
    }
}
Access receipt
●   Follow receipt link
●   $.links[?(@.rel="receipt")].href
●   GET /orders/4711/receipt


                  Conclude order
●   Follow receipt link
●   $.links[?(@.rel="receipt")].href
●   DELETE /orders/4711/receipt
DEMO
Summary
●   Hypermedia — is often overlooked constaint of REST. In exchange you
    get independent evolution and decoupled implementation.
●   Spring HATEOAS - http://bit.ly/spring-hateoas
●   Representation models
●   LinkBuilderAPI
●   Representation enrichment

●   Spring Data REST - http://bit.ly/sd-rest
●   Exports JPA repositories as resources
●   Hypermedia driven representations
●   Extension points

●   REST Shell - github.com/SpringSource/rest-shell
●   Explore REST webservices
●   Hypermedia driven
●   Spring HATEOAS link format

●   Spring RESTBucks - http://bit.ly/spring-restbucks
●   Sample implementation
●   Using Spring technologies

●   Lombok — projectlombok.org
•   get rid of boilerplate
QUESTIONS?

Más contenido relacionado

Similar a Rest on steroids

QLogic Adapters & Virtualized Environments
QLogic Adapters & Virtualized EnvironmentsQLogic Adapters & Virtualized Environments
QLogic Adapters & Virtualized EnvironmentsQLogic Corporation
 
Red Hat Storage - Introduction to GlusterFS
Red Hat Storage - Introduction to GlusterFSRed Hat Storage - Introduction to GlusterFS
Red Hat Storage - Introduction to GlusterFSGlusterFS
 
Cpp In Soa
Cpp In SoaCpp In Soa
Cpp In SoaWSO2
 
Identity Server on Azure: A Reference Architecture
Identity Server on Azure: A Reference ArchitectureIdentity Server on Azure: A Reference Architecture
Identity Server on Azure: A Reference ArchitectureWSO2
 
What's new in confluent platform 5.4 online talk
What's new in confluent platform 5.4 online talkWhat's new in confluent platform 5.4 online talk
What's new in confluent platform 5.4 online talkconfluent
 
Private Clouds - Business Agility Seminar
Private Clouds - Business Agility SeminarPrivate Clouds - Business Agility Seminar
Private Clouds - Business Agility SeminarExponential_e
 
Zingme practice for building scalable website with PHP
Zingme practice for building scalable website with PHPZingme practice for building scalable website with PHP
Zingme practice for building scalable website with PHPChau Thanh
 
Zingme practice for building scalable website with PHP
Zingme practice for building scalable website with PHPZingme practice for building scalable website with PHP
Zingme practice for building scalable website with PHPVõ Duy Tuấn
 
zingmepracticeforbuildingscalablewebsitewithphp
zingmepracticeforbuildingscalablewebsitewithphpzingmepracticeforbuildingscalablewebsitewithphp
zingmepracticeforbuildingscalablewebsitewithphphazzaz
 
01 zingme practice for building scalable website with php
01 zingme practice for building scalable website with php01 zingme practice for building scalable website with php
01 zingme practice for building scalable website with phpNguyen Duc Phu
 
Commonsense Linux sysad and scaling of webapps in the cloud
Commonsense Linux sysad and scaling of webapps in the cloudCommonsense Linux sysad and scaling of webapps in the cloud
Commonsense Linux sysad and scaling of webapps in the cloudmkpai
 
AdaLabs FOSDEM 2012 Ada on Rails
AdaLabs FOSDEM 2012 Ada on RailsAdaLabs FOSDEM 2012 Ada on Rails
AdaLabs FOSDEM 2012 Ada on RailsAdaLabs
 
RedisConf17 - Dynomite - Making Non-distributed Databases Distributed
RedisConf17 - Dynomite - Making Non-distributed Databases DistributedRedisConf17 - Dynomite - Making Non-distributed Databases Distributed
RedisConf17 - Dynomite - Making Non-distributed Databases DistributedRedis Labs
 
Clavister security for virtualized environment
Clavister security for virtualized environmentClavister security for virtualized environment
Clavister security for virtualized environmentnicolasotira
 
Microservices Architecture
Microservices ArchitectureMicroservices Architecture
Microservices ArchitectureLucian Neghina
 

Similar a Rest on steroids (20)

2018 jk
2018 jk2018 jk
2018 jk
 
QLogic Adapters & Virtualized Environments
QLogic Adapters & Virtualized EnvironmentsQLogic Adapters & Virtualized Environments
QLogic Adapters & Virtualized Environments
 
Modern architecture
Modern architectureModern architecture
Modern architecture
 
Red Hat Storage - Introduction to GlusterFS
Red Hat Storage - Introduction to GlusterFSRed Hat Storage - Introduction to GlusterFS
Red Hat Storage - Introduction to GlusterFS
 
Cpp In Soa
Cpp In SoaCpp In Soa
Cpp In Soa
 
Identity Server on Azure: A Reference Architecture
Identity Server on Azure: A Reference ArchitectureIdentity Server on Azure: A Reference Architecture
Identity Server on Azure: A Reference Architecture
 
What's new in confluent platform 5.4 online talk
What's new in confluent platform 5.4 online talkWhat's new in confluent platform 5.4 online talk
What's new in confluent platform 5.4 online talk
 
Private Clouds - Business Agility Seminar
Private Clouds - Business Agility SeminarPrivate Clouds - Business Agility Seminar
Private Clouds - Business Agility Seminar
 
Zingme practice for building scalable website with PHP
Zingme practice for building scalable website with PHPZingme practice for building scalable website with PHP
Zingme practice for building scalable website with PHP
 
Zingme practice for building scalable website with PHP
Zingme practice for building scalable website with PHPZingme practice for building scalable website with PHP
Zingme practice for building scalable website with PHP
 
zingmepracticeforbuildingscalablewebsitewithphp
zingmepracticeforbuildingscalablewebsitewithphpzingmepracticeforbuildingscalablewebsitewithphp
zingmepracticeforbuildingscalablewebsitewithphp
 
01 zingme practice for building scalable website with php
01 zingme practice for building scalable website with php01 zingme practice for building scalable website with php
01 zingme practice for building scalable website with php
 
Dynomite @ RedisConf 2017
Dynomite @ RedisConf 2017Dynomite @ RedisConf 2017
Dynomite @ RedisConf 2017
 
Commonsense Linux sysad and scaling of webapps in the cloud
Commonsense Linux sysad and scaling of webapps in the cloudCommonsense Linux sysad and scaling of webapps in the cloud
Commonsense Linux sysad and scaling of webapps in the cloud
 
AdaLabs FOSDEM 2012 Ada on Rails
AdaLabs FOSDEM 2012 Ada on RailsAdaLabs FOSDEM 2012 Ada on Rails
AdaLabs FOSDEM 2012 Ada on Rails
 
RedisConf17 - Dynomite - Making Non-distributed Databases Distributed
RedisConf17 - Dynomite - Making Non-distributed Databases DistributedRedisConf17 - Dynomite - Making Non-distributed Databases Distributed
RedisConf17 - Dynomite - Making Non-distributed Databases Distributed
 
IBM System Networking SAN24B-5 switch
IBM System Networking SAN24B-5 switchIBM System Networking SAN24B-5 switch
IBM System Networking SAN24B-5 switch
 
Clavister security for virtualized environment
Clavister security for virtualized environmentClavister security for virtualized environment
Clavister security for virtualized environment
 
Microservices Architecture
Microservices ArchitectureMicroservices Architecture
Microservices Architecture
 
Cloud Computing
Cloud ComputingCloud Computing
Cloud Computing
 

Último

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 

Último (20)

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 

Rest on steroids

  • 1. REST on steroids By Andrei Nefyodov
  • 2. Representational State Transfer(REST) — set of architectural constraints Constraint Promotes At the expense of Client-server ●UI portability ●Simplified server ●Multiple organizational domains Stateless ●Simplifiied server Efficiency ● ●Scalability ●Reliability Optional non-shared ●Reduced latency Reliability ● caching ●Efficiency ●Scalability Uniform interface ●Visibility Efficiency ● ●Independent evolution ●Decoupled implementation Layered system ●Shared caching Higher latency ● ●Legacy encapsulation ●Simplified clients ●Scalability ●Load balancing Optional code-on-demand ●Simplified clients Visibility ● ●Extensibility
  • 3. Representational State Transfer(REST) — set of architectural constraints Constraint Promotes At the expense of Sub-constraints: Client-server ●UI portability ● Identification of resources ●Simplified server ● Manipulation via representations ●Multiple organizational domains ● Self-descriptive messages ● Hypemedia as the engine of application state Stateless ●Simplifiied server ●Efficiency ●Scalability ●Reliability Optional non-shared ●Reduced latency ●Reliability caching ●Efficiency ●Scalability Uniform interface ●Visibility ●Efficiency ●Independent evolution ●Decoupled implementation Layered system ●Shared caching ●Higher latency ●Legacy encapsulation ●Simplified clients ●Scalability ●Load balancing Optional code-on-demand ●Simplified clients ●Visibility ●Extensibility
  • 4. Representational State Transfer(REST) — set of architectural constraints Constraint Promotes At the expense of Sub-constraints: Client-server ●UI portability ● Identification of resources ●Simplified server ● Manipulation via representations ●Multiple organizational domains ● Self-descriptive messages ● Hypemedia as the engine of application state Stateless ●Simplifiied server ●Efficiency ●Scalability ●Reliability Optional non-shared ●Reduced latency ●Reliability caching ●Efficiency ●Scalability Uniform interface ●Visibility ●Efficiency ●Independent evolution ●Decoupled implementation You get these if Layered system ●Shared caching you use HTTP latency ●Higher ●Legacy encapsulation as your application protocol ●Simplified clients ●Scalability ●Load balancing Optional code-on-demand ●Simplified clients ●Visibility ●Extensibility
  • 5. Representational State Transfer(REST) — set of architectural constraints Constraint Promotes At the expense of Sub-constraints: Client-server ●UI portability ● Identification of resources ●Simplified server ● Manipulation via representations ●Multiple organizational domains ● Self-descriptive messages ● Hypemedia as the engine of application state Stateless ●Simplifiied server ●Efficiency ●Scalability ●Reliability Optional non-shared ●Reduced latency ●Reliability caching ●Efficiency ●Scalability Uniform interface ●Visibility ●Efficiency ●Independent evolution ●Decoupled implementation Layered system ●Shared caching ●Higher latency ●Legacy encapsulation ●Simplified clients ●Scalability ●Load balancing Optional code-on-demand ●Simplified clients ●Visibility ●Extensibility
  • 6. Hypermedia ● Links in representations ● State navigations discoverable HATEOAS — hypertext as the engine of application state. We express allowed state transitions through links.
  • 7. Hypermedia constraint is an often-overlooked part of being RESTful ● Using Hypermedia aware media type such as collection+json, XHTML promotes ➢ Loose coupling between client and server ➢ Simple documentation of semantic concepts ➢ Discoverability / testability / operability via «API surfing» ● Much of the client framework is reusable
  • 8. RESTBucks ● Starbucks (like) coffee ordering ● Order/payment 5 6 Preparing Ready Completed 4 2 1 Payment expected 3 Cancelled
  • 9. Method URI Action Step POST /orders Create new order 1 PUT/PATCH /orders/4711 Update the order 2 (only if «payment expected») DELETE /orders/4711 Cancel order 3 (only if «payment expected») PUT /orders/4711/payment Pay order 4 Barista preparing the order GET /orders/4711 Poll order state 5 GET /orders/4711/receipt Access reciept DELETE /orders/4711/receipt Conclude the 6 order process
  • 10. Challenges How to avoid hard coding URIs?
  • 12. Orders Returns all orders available in the system Order Returns a single order Self The uri value can be used to GET the latest resource representation of the order. Cancel This is the URI to be used to DELETE the order resource should the consumer wish to cancel the order. Update Consumers can change the order using a POST to transfer a representation to the linked resource. Payment The linked resource allows the consumer to begin paying for an order. Initiating payment involves PUTting an appropriate resource representation to the specified URI. Receipt The URI to access the receipt using GET and conclude the order by taking the receipt (use DELETE).
  • 13. Method Relation type Action Step POST orders Create new order 1 PUT/PATCH update Update the order 2 (only if «payment expected») DELETE cancel Cancel order 3 (only if «payment expected») PUT payment Pay order 4 Barista preparing the order GET order Poll order state 5 GET receipt Access reciept DELETE receipt Conclude the 6 order process
  • 14. Challenges How to implement «only if payment expected»?
  • 15. We can only navigate a link once it was returned by the server
  • 16. Place order ● Access root resource { links : [ { rel : "orders", href : "…/orders" }] } ● Follow orders link $.links[?(@.rel="orders")].href ● POST /orders
  • 17. { links : [{ rel : "self", href : "…/orders/4711" }, … … { rel : "payment", href : "…/orders/4711/payment" } ], content : { items : [{ drink : "Cappucino", size : "large", milk : "semi" price : 4.2 } ], location : "take-away", price : 4.2 status : "payment expected" } }
  • 18. Trigger payment ● Follow payment link ● $.links[?(@.rel="payment")].href ● PUT /orders/4711/payment
  • 19. { links : [{ rel : "self", href : "…/orders/4711/payment" }, { rel : "order", href : "…/orders/4711" } ], content : { creditCard : [{ number : "1234123412341234", cardHolder : "Ivan Ivanov", expiryDate : "2013-11-01" } ], amount : { currency : "EUR", value : 4.2 } } }
  • 20. Poll order ● Follow order link $.links[?(@.rel="order")].href ● GET /orders/4711 ● ETag / If-None-Match
  • 21. { links : [{ rel : "self", href : "…/orders/4711" } ], content : { items : [{ drink : "Cappucino", size : "large", milk : "semi" price : 4.2 } ], location : "take-away", price : 4.2 status : "preparing" } }
  • 22. { links : [{ rel : "self", href : "…/orders/4711" }, { rel : "receipt", href : "…/orders/4711/receipt" } ], content : { items : [{ drink : "Cappucino", size : "large", milk : "semi" price : 4.2 } ], location : "take-away", price : 4.2 status : "ready" } }
  • 23. Access receipt ● Follow receipt link ● $.links[?(@.rel="receipt")].href ● GET /orders/4711/receipt Conclude order ● Follow receipt link ● $.links[?(@.rel="receipt")].href ● DELETE /orders/4711/receipt
  • 24. DEMO
  • 25. Summary ● Hypermedia — is often overlooked constaint of REST. In exchange you get independent evolution and decoupled implementation. ● Spring HATEOAS - http://bit.ly/spring-hateoas ● Representation models ● LinkBuilderAPI ● Representation enrichment ● Spring Data REST - http://bit.ly/sd-rest ● Exports JPA repositories as resources ● Hypermedia driven representations ● Extension points ● REST Shell - github.com/SpringSource/rest-shell ● Explore REST webservices ● Hypermedia driven ● Spring HATEOAS link format ● Spring RESTBucks - http://bit.ly/spring-restbucks ● Sample implementation ● Using Spring technologies ● Lombok — projectlombok.org • get rid of boilerplate