REST and API Management
              with


              Hiranya Jayathilaka
         Product Manager – WSO2 ESB



                      
What is REST?
    ●   REpresentational State Transfer
    ●   Lightweight, Client­Server architecture
    ●   Interactions are based on the transfer of 
        resource state representations
    ●   Systems exchange state representations and 
        perform application state transitions
    ●   Mostly implemented using HTTP but can be 
        based on other protocols
                                
Origin and Growth
    ●   First introduced by Roy Fielding in his doctoral 
        dissertation
    ●   Developed in parallel with HTTP/1.1
    ●   WWW is the largest known implementation of a 
        RESTful architecture
    ●   Widely used in modern days as an alternative to 
        technologies like CORBA and SOAP


                                
REST By Example...
    ●   Learning Management System for a school
    ●   A number of fundamental concepts
        ●   Student
        ●   Course
        ●   Teacher
    ●   In a RESTful design these concepts are likely to 
        become the 'resources' managed by the LMS


                               
The 'Student' Resource State
    ●   Name
    ●   Index number
    ●   Age
    ●   Date of birth
    ●   Contact information
    ●   GPA
    ●   ...
                               
State Representation ­ XML




                 
State Representation ­ JSON




                  
Application State
    ●   Applications have states
        ●   Number of students in the system
        ●   Number of associations between students and 
            courses
        ●   Number of teachers
    ●   Application state transitions may occur as a 
        result of a resource state transfer
    ●   Application state can also be represented using 
        some data format or hyper text references
                                   
Representational State Transfer
    ●   Clients and servers interact with each other by 
        exchanging 
        ●   Resource state representations
        ●   Application state representations
        ●   Other control information




                                    
RESTful Interactions




              
Why HTTP?
    ●   Rich vocabulary and powerful tools that are 
        ideal for representing resource states, 
        application states and control data
        ●   Application state – Status code + Links
        ●   Resource state – HTTP entity
        ●   Control data – HTTP method
    ●   CRUD operations map nicely into HTTP 
        methods

                                    
HTTP Based RESTful Interactions




                    
Advantages
    ●   Simple and lightweight
        ●   Easy to implement
        ●   Very little processing at the application level
        ●   Small amount of data to pass around
    ●   Support any content type
    ●   Leverage built­in application layer protocol 
        semantics without reinventing the wheel


                                     
Notable Deployments
    ●   Amazon AWS (Over 90% of the clients are 
        using the RESTful API)
    ●   Google Maps
    ●   Yahoo!
    ●   eBay
        ●   Sastry Malladi on service orientation ­ 
            http://www.youtube.com/watch?v=O­9osZGXDok


                                
WSO2 ESB
    ●   A lightweight, high­performance ESB
    ●   Feature rich and standards compliant
        ●   SOAP and WS­* standards
        ●   REST support
        ●   Variety of protocols and message formats
    ●   User friendly and highly extensible
    ●   100% free and open source with commercial 
        support
                                   
Under the Hood
    ●   WSO2 ESB is based on a number of well 
        known Apache projects
        ●   Synapse ­ http://synapse.apache.org
        ●   Axis2­ http://axis.apache.org/axis2/java/core
        ●   Web Services ­ http://ws.apache.org
    ●   REST support of WSO2 ESB stems from the 
        REST support offered by Axis2


                                    
REST Support in Axis2
    ●   Axis2 provides a REST binding for each 
        deployed web service
    ●   This enables clients to invoke any Axis2 service 
        via REST calls
        ●   GET /services/HelloService/sayHello
        ●   GET /services/MathService/add?a=5&b=10




                                   
REST Support in WSO2 ESB
    ●   WSO2 ESB can receive and mediate REST 
        calls just like any other request
    ●   The same mediators that work with SOAP can 
        be used to manipulate REST invocations
        ●   Log, Send, Filter, Switch, XSLT, DBLookup....
    ●   Additional handles provided by the ESB in the 
        form of properties
    ●   Easily switch between SOAP and REST
                                    
Exposing a SOAP Service via REST




                
Sample Proxy Configuration




                 
Exposing a REST/POX Service via 
                 SOAP




                    
Sample Proxy Configuration




                 
Exercising More Control Over REST
    ●   Manipulate REST calls based on
        ●   HTTP method
        ●   Status code
        ●   Content type
        ●   HTTP headers




                             
Accessing HTTP Method




               
Examples




        
Accessing HTTP Status Codes




                  
Examples




        
Manipulating HTTP Headers




                 
Examples




        
REST APIs
    ●   An API is similar to a web application hosted on 
        the ESB
    ●   Anchored at a specific URL path (context)
        ●   /test
        ●   /dictionary
        ●   /foo/bar
    ●   Can be bound to a specific host and a port
    ●   Contains one or more resources
                                
Resources
    ●   A RESTful resource exposed over HTTP
    ●   Similar to a proxy service but focuses on REST
    ●   Can be associated with
        ●   A set of HTTP methods
            –   GET only, GET and POST only, All HTTP methods
        ●   A specific content type
            –   application/xml, application/json
        ●   A particular class of clients (user agents)

                                         
Dispatching Requests to a Resource
    ●   URL patterns
        ●   Reg­Ex match (/test/*)
        ●   Extension match (*.jsp)
        ●   Exact match (/test/index.jsp)
    ●   URI templates
        ●   /dictionary/{character}/{word}
        ●   /accounts/{accountId}/{operation}


                                      
APIs and Resources




             
Resource Examples




             
API Example




          
APIs in Action




           
API Management Goals
    ●   Service provider objectives
        ●   Define APIs
        ●   Define security requirements and SLAs
        ●   Monitor API usage and SLAs
    ●   Service consumer objectives
        ●   Discover and browse APIs
        ●   Sign up and obtain API keys
        ●   Consume APIs using the obtained keys
        ●   Monitor API usage and SLAs
                                     
Solution Architecture




               
WSO2 Product Mapping




              
Summary and Recap
    ●   REST is a lightweight, client­server architecture for building 
        distributed systems
    ●   RESTful designs are concerned with resources, states and 
        transfer of representational state between systems
    ●   WSO2 ESB provides excellent support for receiving, processing 
        and intermediating REST (HTTP) calls
    ●   The new API concept is a powerful feature which allows 
        developers to define REST APIs in the ESB without writing any 
        additional code
    ●   WSO2 platform is ideally suited for developing comprehensive and 
        flexible API management solutions based on open standards

                                          
Questions?




         
Selected Customers




             
WSO2 Engagement Model
    ●   Quick Start
    ●   Development Support
    ●   Development Services
    ●   Production Support
    ●   Turnkey Solutions
        ●   WSO2 Mobile Services Solution
        ●   WSO2 FIX Gateway Solution
        ●   WSO2 SAP Gateway Solution
                                  
Thank You




         

REST & API Management with the WSO2 ESB

  • 1.
    REST and API Management with Hiranya Jayathilaka Product Manager – WSO2 ESB    
  • 2.
    What is REST? ● REpresentational State Transfer ● Lightweight, Client­Server architecture ● Interactions are based on the transfer of  resource state representations ● Systems exchange state representations and  perform application state transitions ● Mostly implemented using HTTP but can be  based on other protocols    
  • 3.
    Origin and Growth ● First introduced by Roy Fielding in his doctoral  dissertation ● Developed in parallel with HTTP/1.1 ● WWW is the largest known implementation of a  RESTful architecture ● Widely used in modern days as an alternative to  technologies like CORBA and SOAP    
  • 4.
    REST By Example... ● Learning Management System for a school ● A number of fundamental concepts ● Student ● Course ● Teacher ● In a RESTful design these concepts are likely to  become the 'resources' managed by the LMS    
  • 5.
    The 'Student' Resource State ● Name ● Index number ● Age ● Date of birth ● Contact information ● GPA ● ...    
  • 6.
  • 7.
  • 8.
    Application State ● Applications have states ● Number of students in the system ● Number of associations between students and  courses ● Number of teachers ● Application state transitions may occur as a  result of a resource state transfer ● Application state can also be represented using  some data format or hyper text references    
  • 9.
    Representational State Transfer ● Clients and servers interact with each other by  exchanging  ● Resource state representations ● Application state representations ● Other control information    
  • 10.
  • 11.
    Why HTTP? ● Rich vocabulary and powerful tools that are  ideal for representing resource states,  application states and control data ● Application state – Status code + Links ● Resource state – HTTP entity ● Control data – HTTP method ● CRUD operations map nicely into HTTP  methods    
  • 12.
  • 13.
    Advantages ● Simple and lightweight ● Easy to implement ● Very little processing at the application level ● Small amount of data to pass around ● Support any content type ● Leverage built­in application layer protocol  semantics without reinventing the wheel    
  • 14.
    Notable Deployments ● Amazon AWS (Over 90% of the clients are  using the RESTful API) ● Google Maps ● Yahoo! ● eBay ● Sastry Malladi on service orientation ­  http://www.youtube.com/watch?v=O­9osZGXDok    
  • 15.
    WSO2 ESB ● A lightweight, high­performance ESB ● Feature rich and standards compliant ● SOAP and WS­* standards ● REST support ● Variety of protocols and message formats ● User friendly and highly extensible ● 100% free and open source with commercial  support    
  • 16.
    Under the Hood ● WSO2 ESB is based on a number of well  known Apache projects ● Synapse ­ http://synapse.apache.org ● Axis2­ http://axis.apache.org/axis2/java/core ● Web Services ­ http://ws.apache.org ● REST support of WSO2 ESB stems from the  REST support offered by Axis2    
  • 17.
    REST Support in Axis2 ● Axis2 provides a REST binding for each  deployed web service ● This enables clients to invoke any Axis2 service  via REST calls ● GET /services/HelloService/sayHello ● GET /services/MathService/add?a=5&b=10    
  • 18.
    REST Support in WSO2 ESB ● WSO2 ESB can receive and mediate REST  calls just like any other request ● The same mediators that work with SOAP can  be used to manipulate REST invocations ● Log, Send, Filter, Switch, XSLT, DBLookup.... ● Additional handles provided by the ESB in the  form of properties ● Easily switch between SOAP and REST    
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
    Exercising More Control Over REST ● Manipulate REST calls based on ● HTTP method ● Status code ● Content type ● HTTP headers    
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
    REST APIs ● An API is similar to a web application hosted on  the ESB ● Anchored at a specific URL path (context) ● /test ● /dictionary ● /foo/bar ● Can be bound to a specific host and a port ● Contains one or more resources    
  • 31.
    Resources ● A RESTful resource exposed over HTTP ● Similar to a proxy service but focuses on REST ● Can be associated with ● A set of HTTP methods – GET only, GET and POST only, All HTTP methods ● A specific content type – application/xml, application/json ● A particular class of clients (user agents)    
  • 32.
    Dispatching Requests to a Resource ● URL patterns ● Reg­Ex match (/test/*) ● Extension match (*.jsp) ● Exact match (/test/index.jsp) ● URI templates ● /dictionary/{character}/{word} ● /accounts/{accountId}/{operation}    
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
    API Management Goals ● Service provider objectives ● Define APIs ● Define security requirements and SLAs ● Monitor API usage and SLAs ● Service consumer objectives ● Discover and browse APIs ● Sign up and obtain API keys ● Consume APIs using the obtained keys ● Monitor API usage and SLAs    
  • 38.
  • 39.
  • 40.
    Summary and Recap ● REST is a lightweight, client­server architecture for building  distributed systems ● RESTful designs are concerned with resources, states and  transfer of representational state between systems ● WSO2 ESB provides excellent support for receiving, processing  and intermediating REST (HTTP) calls ● The new API concept is a powerful feature which allows  developers to define REST APIs in the ESB without writing any  additional code ● WSO2 platform is ideally suited for developing comprehensive and  flexible API management solutions based on open standards    
  • 41.
  • 42.
  • 43.
    WSO2 Engagement Model ● Quick Start ● Development Support ● Development Services ● Production Support ● Turnkey Solutions ● WSO2 Mobile Services Solution ● WSO2 FIX Gateway Solution ● WSO2 SAP Gateway Solution    
  • 44.