SlideShare a Scribd company logo
1 of 30
Stop Making The Web
   Harder Than It Is;
Real-world REST, HATEOAS, and Hypermedia
             APIs with Magpie
                Kip Hampton
          Senior Architect, Tamarou
                       @kiphampton
                   https://github.com/ubu
         https://metacpan.org/author/KHAMPTON
I’m looking at you,
      gphat...
ZOMG Teh Future!
Haha, Only Serious
•   Dedicated Hypermedia Type (HTML)
•   Communication sent over HTTP using the
    standard verbs. (GET, POST)
•   Data contains embedded, discoverable links to
    related resources and addditional metadata.
•   Raw payload meaningful to both humans and
    specialized clients.
Why Is The Web Still Hard?
•   We invented (then re-invented) new things
    instead of using all that HTTP offered.
•   We overburdened the things we did use.
•   We applied the wrong design patterns (MVC).
REST == Using All Of HTTP
•   HTTP Verbs (GET, POST, PUT, DELETE, etc)
•   Status Codes (there's more to life than 200
    OK)
•   Headers (Link, ETag, X-* custom headers)
•   Media Types (Be inventive!)
Sorry, HATEOASers
•       Hypermedia as the Engine of Application State
•       Don't make the client have to guess (or
        already know) what to do next.
    o    Think: HTML Links, Forms
    o    Custom media types especially useful.
Hypertext Application Language

•   Simple, lightweight.
•   Comprehensible to both human and automated
    clients.
•   Associated Resources can be embedded or linked
    to.
•   Available in both JSON and XML formats.
•   More at: http://stateless.co/hal_specification.html
HAL (JSON)
{
     "_links": {
        "self": { "href": "/orders" },
        "next": { "href": "/orders?page=2" },
        "find": { "href": "/orders{?id}", "templated": true }
     },
     "_embedded": {
        "orders": [{
             "_links": {
               "self": { "href": "/orders/123" },
               "basket": { "href": "/baskets/98712" },
               "customer": { "href": "/customers/7809" }
             },
             "total": 30.00,
             "currency": "USD",
             "status": "shipped",
           },{
             "_links": {
               "self": { "href": "/orders/124" },
               "basket": { "href": "/baskets/97213" },
               "customer": { "href": "/customers/12369" }
             },
             "total": 20.00,
             "currency": "USD",
             "status": "processing"
        }]
     },
     currentlyProcessing: 14,
     shippedToday: 20
 }
}
"A resource is not the thing
that is transferred across the
wire or picked up off the disk
or seen from afar while walking
your dog. Each of those is only
a representation."

Roy Fielding, 2002
The Resource Is
 Not The Thing
Introducing Magpie
• Built specifically with Resource-oriented
  development in mind.
• Uses a event-based pipeline processing model.
 o Configuration determines which components
    are loaded into the pipeline.
 o Components determine which of their event
    methods will fire.
• Implemented via Plack::Middleware::Magpie.
Hello, Magpie
use Plack::Builder;
use Plack::Middleware::Magpie;
my $docroot = ‘/some/path/to/htdocs’;

my $app = builder {
    enable "Magpie",
        pipeline => [
           'Magpie::Transformer::XSLT' =>
            { stylesheet => “$docroot/stylesheets/hello.xsl” }
        ];

     enable "Static", path => qr!.xml$!, root => $docroot;
};

$app;

 • Single pipeline component.
 • Resource data passed from upstream middleware.
Dispatching
•    The URL path is only part of the equation.
•    Dispatching happens on two levels:
    1. Which components will be loaded into the
       pipeline?
    2. Which event methods will be fired within
       those components?
Loading Components
•       Application pipelines are defined via configuration
        (Plack::Builder-like DSL, or XML file).
•       Several options:
    •     Static pipelines.
    •     Dynamic pipelines via the machine() keyword and
          one or more of the match* options.
•       Components are added top-down, in configuration
        order.
Dynamic Pipelines
    Dynamic component loading via the machine()
       keyword.
    •   match -- Adds component(s) conditionally based
        on string equality or regular expression match
        against the request’s path.
enable "Magpie", pipeline => [
machine {
    match qr|^/api/cast-member| => [‘MyApp::Resource::CastMember’],
    match qr|^/api/prop|        => [‘MyApp::Resource::Prop’],
}
    MyApp::Serializer::JSON,
];
Dynamic Pipelines (cont’d)
•   match_template -- Adds component(s)
    conditionally based on regular expression match
    and uses URI Template-like brackets ({}) to capture
    param/value pairs.
•   match_env -- Adds component(s) by evaluating
    an anonymous subroutine which is passed the Plack
    environment hash at request time.
•   match_accept -- Adds component(s) by
    evaluating a content negotiation matrix against the
    Accept* headers of the incoming request.
Event Dispatching
•   Each component class controls its own event dispatching.
•   Standard event models.
    o   Magpie::Dispatcher::RequestMethod
    o   Magpie::Dispatcher::RequestParam
•   Easy to roll your own.
    o   Write your event methods,
    o   Register the methods you want Magpie to know about,
    o   Implement load_queue() to define which events fire
        under what circumstances.
Do I really need all
       that?
Simple Resource
package MyApp::Resource::Widget;
use Moose;
extends 'Magpie::Resource';
use Magpie::Constants;

sub GET {
    my ($self, $context) = @_;
    $self->parent_handler->resource($self);

    my $data = $self->however_you_get_widget_data(%some_args);

    unless ($data) {
        $self->set_error({
            status_code => 404,
            reason => 'Resource not found.'
        });
        return DONE;
    }

    $self->data($data);
    return OK;
}
If there's no Model
 and the Resource
 is not The Thing,
  where does stuff
         go?
Assets
•   Each Magpie application has a Bread::Board
    container to hold the things required to implement
    your Resource classes and other components.
•   Assets can be added both via the DSL and the XML
    config. (merged at start-up).
•   Available in each component class
    $dbh = $self->resolve_asset( service => 'db_handle');
But Wait!




There's more!
Extras
•   Existing Plack::Middleware::* classes can be used as
    pipeline components with no modification.
•   Component class event methods have full access to
    the pipeline and can end the processing chain, add
    or remove components, etc.
•   Component base classes offer a predictable set of
    convenience attibutes for operating on the
    incoming request, the outgoing response, the
    current resource class, etc.
•   All component classes are Trait-aware from the
    start.
What's There?
•   A solid, stable, tested core.
•   Workable APIs for various common component
    types (Resources, Transformers, Plugins,
    Dispatchers).
•   Small but growing number of general components.
    (KiokuDB and File Resources, XSLT, Template
    Toolkit Transformers, etc.)
•   A committed core of developers.
What's Missing?
•   Docs, docs, docs.
•   Many more generic component classes.
•   Bootstrap profiles for common types of
    applications.
•   Magpie GUI.
•   Mostly, what Magpie needs right now is…
YOU!
Questions?
Thank You
More Information
• GitHub:
 https://github.com/Tamarou/magpie
• IRC:
 irc.perl.org #magpie
• Mailing List:
 http://magpie-lists.tamarou.com/listinfo/devel

• Hallway++
 Barge right up and ask!

More Related Content

What's hot

Introducing Riak
Introducing RiakIntroducing Riak
Introducing RiakKevin Smith
 
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSONAn introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSONSyed Moosa Kaleem
 
WordPress Café: Using WordPress as a Framework
WordPress Café: Using WordPress as a FrameworkWordPress Café: Using WordPress as a Framework
WordPress Café: Using WordPress as a FrameworkExove
 
OSCON 2011 CouchApps
OSCON 2011 CouchAppsOSCON 2011 CouchApps
OSCON 2011 CouchAppsBradley Holt
 
Cloud Security Monitoring and Spark Analytics
Cloud Security Monitoring and Spark AnalyticsCloud Security Monitoring and Spark Analytics
Cloud Security Monitoring and Spark Analyticsamesar0
 
Open Standards for the Semantic Web: XML / RDF(S) / OWL / SOAP
Open Standards for the Semantic Web: XML / RDF(S) / OWL / SOAPOpen Standards for the Semantic Web: XML / RDF(S) / OWL / SOAP
Open Standards for the Semantic Web: XML / RDF(S) / OWL / SOAPPieter De Leenheer
 
Building Beautiful REST APIs in ASP.NET Core
Building Beautiful REST APIs in ASP.NET CoreBuilding Beautiful REST APIs in ASP.NET Core
Building Beautiful REST APIs in ASP.NET CoreStormpath
 
Drupal security
Drupal securityDrupal security
Drupal securityJozef Toth
 
Beautiful REST+JSON APIs with Ion
Beautiful REST+JSON APIs with IonBeautiful REST+JSON APIs with Ion
Beautiful REST+JSON APIs with IonStormpath
 
Building Beautiful REST APIs in ASP.NET Core
Building Beautiful REST APIs in ASP.NET CoreBuilding Beautiful REST APIs in ASP.NET Core
Building Beautiful REST APIs in ASP.NET CoreNate Barbettini
 
Cwinters Intro To Rest And JerREST and Jersey Introductionsey
Cwinters Intro To Rest And JerREST and Jersey IntroductionseyCwinters Intro To Rest And JerREST and Jersey Introductionsey
Cwinters Intro To Rest And JerREST and Jersey Introductionseyelliando dias
 
Elasticsearch in 15 minutes
Elasticsearch in 15 minutesElasticsearch in 15 minutes
Elasticsearch in 15 minutesDavid Pilato
 
Riak 2.0 : For Beginners, and Everyone Else
Riak 2.0 : For Beginners, and Everyone ElseRiak 2.0 : For Beginners, and Everyone Else
Riak 2.0 : For Beginners, and Everyone ElseEngin Yoeyen
 
The never-ending REST API design debate -- Devoxx France 2016
The never-ending REST API design debate -- Devoxx France 2016The never-ending REST API design debate -- Devoxx France 2016
The never-ending REST API design debate -- Devoxx France 2016Restlet
 
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswani
Creating REST Applications with the Slim Micro-Framework by Vikram VaswaniCreating REST Applications with the Slim Micro-Framework by Vikram Vaswani
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswanivvaswani
 

What's hot (20)

Introducing Riak
Introducing RiakIntroducing Riak
Introducing Riak
 
Develop webservice in PHP
Develop webservice in PHPDevelop webservice in PHP
Develop webservice in PHP
 
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSONAn introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON
An introduction to DOM , JAVASCRIPT , JQUERY, AJAX and JSON
 
WordPress Café: Using WordPress as a Framework
WordPress Café: Using WordPress as a FrameworkWordPress Café: Using WordPress as a Framework
WordPress Café: Using WordPress as a Framework
 
OSCON 2011 CouchApps
OSCON 2011 CouchAppsOSCON 2011 CouchApps
OSCON 2011 CouchApps
 
Cloud Security Monitoring and Spark Analytics
Cloud Security Monitoring and Spark AnalyticsCloud Security Monitoring and Spark Analytics
Cloud Security Monitoring and Spark Analytics
 
Jsp
JspJsp
Jsp
 
Open Standards for the Semantic Web: XML / RDF(S) / OWL / SOAP
Open Standards for the Semantic Web: XML / RDF(S) / OWL / SOAPOpen Standards for the Semantic Web: XML / RDF(S) / OWL / SOAP
Open Standards for the Semantic Web: XML / RDF(S) / OWL / SOAP
 
Building Beautiful REST APIs in ASP.NET Core
Building Beautiful REST APIs in ASP.NET CoreBuilding Beautiful REST APIs in ASP.NET Core
Building Beautiful REST APIs in ASP.NET Core
 
Drupal security
Drupal securityDrupal security
Drupal security
 
Beautiful REST+JSON APIs with Ion
Beautiful REST+JSON APIs with IonBeautiful REST+JSON APIs with Ion
Beautiful REST+JSON APIs with Ion
 
Building Beautiful REST APIs in ASP.NET Core
Building Beautiful REST APIs in ASP.NET CoreBuilding Beautiful REST APIs in ASP.NET Core
Building Beautiful REST APIs in ASP.NET Core
 
Cwinters Intro To Rest And JerREST and Jersey Introductionsey
Cwinters Intro To Rest And JerREST and Jersey IntroductionseyCwinters Intro To Rest And JerREST and Jersey Introductionsey
Cwinters Intro To Rest And JerREST and Jersey Introductionsey
 
Linked Process
Linked ProcessLinked Process
Linked Process
 
Elasticsearch in 15 minutes
Elasticsearch in 15 minutesElasticsearch in 15 minutes
Elasticsearch in 15 minutes
 
Hows Haml?
Hows Haml?Hows Haml?
Hows Haml?
 
Riak 2.0 : For Beginners, and Everyone Else
Riak 2.0 : For Beginners, and Everyone ElseRiak 2.0 : For Beginners, and Everyone Else
Riak 2.0 : For Beginners, and Everyone Else
 
The never-ending REST API design debate -- Devoxx France 2016
The never-ending REST API design debate -- Devoxx France 2016The never-ending REST API design debate -- Devoxx France 2016
The never-ending REST API design debate -- Devoxx France 2016
 
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswani
Creating REST Applications with the Slim Micro-Framework by Vikram VaswaniCreating REST Applications with the Slim Micro-Framework by Vikram Vaswani
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswani
 
Jquery 4
Jquery 4Jquery 4
Jquery 4
 

Viewers also liked

Introduction to PhoneGap
Introduction to PhoneGapIntroduction to PhoneGap
Introduction to PhoneGapRamesh Nair
 
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)Dotan Dimet
 
Building a MongoDB App with Perl
Building a MongoDB App with PerlBuilding a MongoDB App with Perl
Building a MongoDB App with PerlMike Friedman
 
Amazon DynamoDB Lessen's Learned by Beginner
Amazon DynamoDB Lessen's Learned by BeginnerAmazon DynamoDB Lessen's Learned by Beginner
Amazon DynamoDB Lessen's Learned by BeginnerHirokazu Tokuno
 
Introduction to PhoneGap
Introduction to PhoneGapIntroduction to PhoneGap
Introduction to PhoneGapQuang Minh Dao
 

Viewers also liked (9)

REST in Practice
REST in PracticeREST in Practice
REST in Practice
 
Introduction to PhoneGap
Introduction to PhoneGapIntroduction to PhoneGap
Introduction to PhoneGap
 
All About Phonegap
All About Phonegap All About Phonegap
All About Phonegap
 
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
Mojolicious - Perl Framework for the Real-Time Web (Lightning Talk)
 
Building a MongoDB App with Perl
Building a MongoDB App with PerlBuilding a MongoDB App with Perl
Building a MongoDB App with Perl
 
Amazon DynamoDB Lessen's Learned by Beginner
Amazon DynamoDB Lessen's Learned by BeginnerAmazon DynamoDB Lessen's Learned by Beginner
Amazon DynamoDB Lessen's Learned by Beginner
 
Introduction to PhoneGap
Introduction to PhoneGapIntroduction to PhoneGap
Introduction to PhoneGap
 
Phone gap
Phone gapPhone gap
Phone gap
 
Mojolicious and REST
Mojolicious and RESTMojolicious and REST
Mojolicious and REST
 

Similar to Stop Making The Web Harder Than It Is; Real-world REST, HATEOAS, and Hypermedia APIs with Magpie

An Introduction to Tornado
An Introduction to TornadoAn Introduction to Tornado
An Introduction to TornadoGavin Roy
 
Big data, just an introduction to Hadoop and Scripting Languages
Big data, just an introduction to Hadoop and Scripting LanguagesBig data, just an introduction to Hadoop and Scripting Languages
Big data, just an introduction to Hadoop and Scripting LanguagesCorley S.r.l.
 
Uni w pachube 111108
Uni w pachube 111108Uni w pachube 111108
Uni w pachube 111108Paul Tanner
 
Web Services PHP Tutorial
Web Services PHP TutorialWeb Services PHP Tutorial
Web Services PHP TutorialLorna Mitchell
 
Optimization of modern web applications
Optimization of modern web applicationsOptimization of modern web applications
Optimization of modern web applicationsEugene Lazutkin
 
Hypermedia System Architecture for a Web of Things
Hypermedia System Architecture for a Web of ThingsHypermedia System Architecture for a Web of Things
Hypermedia System Architecture for a Web of ThingsMichael Koster
 
Practical catalyst
Practical catalystPractical catalyst
Practical catalystdwm042
 
Applied Machine learning using H2O, python and R Workshop
Applied Machine learning using H2O, python and R WorkshopApplied Machine learning using H2O, python and R Workshop
Applied Machine learning using H2O, python and R WorkshopAvkash Chauhan
 
Galaxy
GalaxyGalaxy
Galaxybosc
 
GDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App EngineGDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App EngineYared Ayalew
 
1.6 米嘉 gobuildweb
1.6 米嘉 gobuildweb1.6 米嘉 gobuildweb
1.6 米嘉 gobuildwebLeo Zhou
 
Office 365 Saturday (Sydney) - SharePoint framework – build integrated user e...
Office 365 Saturday (Sydney) - SharePoint framework – build integrated user e...Office 365 Saturday (Sydney) - SharePoint framework – build integrated user e...
Office 365 Saturday (Sydney) - SharePoint framework – build integrated user e...Anupam Ranku
 
Creating PostgreSQL-as-a-Service at Scale
Creating PostgreSQL-as-a-Service at ScaleCreating PostgreSQL-as-a-Service at Scale
Creating PostgreSQL-as-a-Service at ScaleSean Chittenden
 
Php on the Web and Desktop
Php on the Web and DesktopPhp on the Web and Desktop
Php on the Web and DesktopElizabeth Smith
 
Composing re-useable ETL on Hadoop
Composing re-useable ETL on HadoopComposing re-useable ETL on Hadoop
Composing re-useable ETL on HadoopPaul Lam
 
Building Hadoop Data Applications with Kite
Building Hadoop Data Applications with KiteBuilding Hadoop Data Applications with Kite
Building Hadoop Data Applications with Kitehuguk
 

Similar to Stop Making The Web Harder Than It Is; Real-world REST, HATEOAS, and Hypermedia APIs with Magpie (20)

An Introduction to Tornado
An Introduction to TornadoAn Introduction to Tornado
An Introduction to Tornado
 
REST easy with API Platform
REST easy with API PlatformREST easy with API Platform
REST easy with API Platform
 
Big data, just an introduction to Hadoop and Scripting Languages
Big data, just an introduction to Hadoop and Scripting LanguagesBig data, just an introduction to Hadoop and Scripting Languages
Big data, just an introduction to Hadoop and Scripting Languages
 
Uni w pachube 111108
Uni w pachube 111108Uni w pachube 111108
Uni w pachube 111108
 
Web Services PHP Tutorial
Web Services PHP TutorialWeb Services PHP Tutorial
Web Services PHP Tutorial
 
Optimization of modern web applications
Optimization of modern web applicationsOptimization of modern web applications
Optimization of modern web applications
 
Hypermedia System Architecture for a Web of Things
Hypermedia System Architecture for a Web of ThingsHypermedia System Architecture for a Web of Things
Hypermedia System Architecture for a Web of Things
 
Practical catalyst
Practical catalystPractical catalyst
Practical catalyst
 
Applied Machine learning using H2O, python and R Workshop
Applied Machine learning using H2O, python and R WorkshopApplied Machine learning using H2O, python and R Workshop
Applied Machine learning using H2O, python and R Workshop
 
Galaxy
GalaxyGalaxy
Galaxy
 
GDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App EngineGDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App Engine
 
Web services tutorial
Web services tutorialWeb services tutorial
Web services tutorial
 
Web Services Tutorial
Web Services TutorialWeb Services Tutorial
Web Services Tutorial
 
1.6 米嘉 gobuildweb
1.6 米嘉 gobuildweb1.6 米嘉 gobuildweb
1.6 米嘉 gobuildweb
 
Office 365 Saturday (Sydney) - SharePoint framework – build integrated user e...
Office 365 Saturday (Sydney) - SharePoint framework – build integrated user e...Office 365 Saturday (Sydney) - SharePoint framework – build integrated user e...
Office 365 Saturday (Sydney) - SharePoint framework – build integrated user e...
 
Creating PostgreSQL-as-a-Service at Scale
Creating PostgreSQL-as-a-Service at ScaleCreating PostgreSQL-as-a-Service at Scale
Creating PostgreSQL-as-a-Service at Scale
 
Intro to JavaScript
Intro to JavaScriptIntro to JavaScript
Intro to JavaScript
 
Php on the Web and Desktop
Php on the Web and DesktopPhp on the Web and Desktop
Php on the Web and Desktop
 
Composing re-useable ETL on Hadoop
Composing re-useable ETL on HadoopComposing re-useable ETL on Hadoop
Composing re-useable ETL on Hadoop
 
Building Hadoop Data Applications with Kite
Building Hadoop Data Applications with KiteBuilding Hadoop Data Applications with Kite
Building Hadoop Data Applications with Kite
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
[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
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
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
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
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
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
🐬 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
 
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
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
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
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
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
 

Recently uploaded (20)

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
[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
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
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...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
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...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
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
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
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...
 

Stop Making The Web Harder Than It Is; Real-world REST, HATEOAS, and Hypermedia APIs with Magpie

  • 1. Stop Making The Web Harder Than It Is; Real-world REST, HATEOAS, and Hypermedia APIs with Magpie Kip Hampton Senior Architect, Tamarou @kiphampton https://github.com/ubu https://metacpan.org/author/KHAMPTON
  • 2. I’m looking at you, gphat...
  • 4. Haha, Only Serious • Dedicated Hypermedia Type (HTML) • Communication sent over HTTP using the standard verbs. (GET, POST) • Data contains embedded, discoverable links to related resources and addditional metadata. • Raw payload meaningful to both humans and specialized clients.
  • 5. Why Is The Web Still Hard? • We invented (then re-invented) new things instead of using all that HTTP offered. • We overburdened the things we did use. • We applied the wrong design patterns (MVC).
  • 6. REST == Using All Of HTTP • HTTP Verbs (GET, POST, PUT, DELETE, etc) • Status Codes (there's more to life than 200 OK) • Headers (Link, ETag, X-* custom headers) • Media Types (Be inventive!)
  • 7. Sorry, HATEOASers • Hypermedia as the Engine of Application State • Don't make the client have to guess (or already know) what to do next. o Think: HTML Links, Forms o Custom media types especially useful.
  • 8. Hypertext Application Language • Simple, lightweight. • Comprehensible to both human and automated clients. • Associated Resources can be embedded or linked to. • Available in both JSON and XML formats. • More at: http://stateless.co/hal_specification.html
  • 9. HAL (JSON) { "_links": { "self": { "href": "/orders" }, "next": { "href": "/orders?page=2" }, "find": { "href": "/orders{?id}", "templated": true } }, "_embedded": { "orders": [{ "_links": { "self": { "href": "/orders/123" }, "basket": { "href": "/baskets/98712" }, "customer": { "href": "/customers/7809" } }, "total": 30.00, "currency": "USD", "status": "shipped", },{ "_links": { "self": { "href": "/orders/124" }, "basket": { "href": "/baskets/97213" }, "customer": { "href": "/customers/12369" } }, "total": 20.00, "currency": "USD", "status": "processing" }] }, currentlyProcessing: 14, shippedToday: 20 } }
  • 10. "A resource is not the thing that is transferred across the wire or picked up off the disk or seen from afar while walking your dog. Each of those is only a representation." Roy Fielding, 2002
  • 11. The Resource Is Not The Thing
  • 12. Introducing Magpie • Built specifically with Resource-oriented development in mind. • Uses a event-based pipeline processing model. o Configuration determines which components are loaded into the pipeline. o Components determine which of their event methods will fire. • Implemented via Plack::Middleware::Magpie.
  • 13. Hello, Magpie use Plack::Builder; use Plack::Middleware::Magpie; my $docroot = ‘/some/path/to/htdocs’; my $app = builder { enable "Magpie", pipeline => [ 'Magpie::Transformer::XSLT' => { stylesheet => “$docroot/stylesheets/hello.xsl” } ]; enable "Static", path => qr!.xml$!, root => $docroot; }; $app; • Single pipeline component. • Resource data passed from upstream middleware.
  • 14. Dispatching • The URL path is only part of the equation. • Dispatching happens on two levels: 1. Which components will be loaded into the pipeline? 2. Which event methods will be fired within those components?
  • 15. Loading Components • Application pipelines are defined via configuration (Plack::Builder-like DSL, or XML file). • Several options: • Static pipelines. • Dynamic pipelines via the machine() keyword and one or more of the match* options. • Components are added top-down, in configuration order.
  • 16. Dynamic Pipelines Dynamic component loading via the machine() keyword. • match -- Adds component(s) conditionally based on string equality or regular expression match against the request’s path. enable "Magpie", pipeline => [ machine { match qr|^/api/cast-member| => [‘MyApp::Resource::CastMember’], match qr|^/api/prop| => [‘MyApp::Resource::Prop’], } MyApp::Serializer::JSON, ];
  • 17. Dynamic Pipelines (cont’d) • match_template -- Adds component(s) conditionally based on regular expression match and uses URI Template-like brackets ({}) to capture param/value pairs. • match_env -- Adds component(s) by evaluating an anonymous subroutine which is passed the Plack environment hash at request time. • match_accept -- Adds component(s) by evaluating a content negotiation matrix against the Accept* headers of the incoming request.
  • 18. Event Dispatching • Each component class controls its own event dispatching. • Standard event models. o Magpie::Dispatcher::RequestMethod o Magpie::Dispatcher::RequestParam • Easy to roll your own. o Write your event methods, o Register the methods you want Magpie to know about, o Implement load_queue() to define which events fire under what circumstances.
  • 19. Do I really need all that?
  • 20. Simple Resource package MyApp::Resource::Widget; use Moose; extends 'Magpie::Resource'; use Magpie::Constants; sub GET { my ($self, $context) = @_; $self->parent_handler->resource($self); my $data = $self->however_you_get_widget_data(%some_args); unless ($data) { $self->set_error({ status_code => 404, reason => 'Resource not found.' }); return DONE; } $self->data($data); return OK; }
  • 21. If there's no Model and the Resource is not The Thing, where does stuff go?
  • 22. Assets • Each Magpie application has a Bread::Board container to hold the things required to implement your Resource classes and other components. • Assets can be added both via the DSL and the XML config. (merged at start-up). • Available in each component class $dbh = $self->resolve_asset( service => 'db_handle');
  • 24. Extras • Existing Plack::Middleware::* classes can be used as pipeline components with no modification. • Component class event methods have full access to the pipeline and can end the processing chain, add or remove components, etc. • Component base classes offer a predictable set of convenience attibutes for operating on the incoming request, the outgoing response, the current resource class, etc. • All component classes are Trait-aware from the start.
  • 25. What's There? • A solid, stable, tested core. • Workable APIs for various common component types (Resources, Transformers, Plugins, Dispatchers). • Small but growing number of general components. (KiokuDB and File Resources, XSLT, Template Toolkit Transformers, etc.) • A committed core of developers.
  • 26. What's Missing? • Docs, docs, docs. • Many more generic component classes. • Bootstrap profiles for common types of applications. • Magpie GUI. • Mostly, what Magpie needs right now is…
  • 27. YOU!
  • 30. More Information • GitHub: https://github.com/Tamarou/magpie • IRC: irc.perl.org #magpie • Mailing List: http://magpie-lists.tamarou.com/listinfo/devel • Hallway++ Barge right up and ask!