Post on 18-Nov-2014
description
WSO2 ESB Integration with REST
Dushan Abeyruwan Associate Tech Lead, Integration Tech Group
Ravi Undupitiya
Software Engineer, Integration Tech Group
About WSO2
• Providing the only complete open source componentized cloud platform
– Dedicated to removing all the stumbling blocks to enterprise agility – Enabling you to focus on business logic and business value
• Recognized by leading analyst firms as visionaries and leaders – Gartner cites WSO2 as visionaries in all 3 categories of application
infrastructure – Forrester places WSO2 in top 2 for API Management
• Global corporation with offices in USA, UK & Sri Lanka
– 200+ employees and growing
• Business model of selling comprehensive support & maintenance for our products
150+ globally positioned support customers
Background
• Service Oriented Architecture (SOA) – A style of so:ware architecture that is modular, distributed and loosely coupled.
– ComponenBzaBon – The main driver of SOA – Business FuncBonaliBes are implemented in different Business Components
– Business Components provide their funcBonality to its consumers as a ‘Service’ with the well-‐defined service interfaces.
Background
• Enterprise Service Bus (ESB) – An ESB is a middleware soluBon that enables interoperability among heterogeneous environments using a service-‐oriented model.
– Stateless and Seamless IntegraBon – Standard Protocols – SOAP, REST, JSON etc. – Transports – HTTP/S, JMS, TCP, VFS etc.
Source : http://graegert.com/programming/no-soa-criticism-somewhere
Under the Hood: Apache Synapse
• A lightweight, open source ESB implementaBon from the
ASF : hXp://synapse.apache.org
• Makes up the mediaBon engine of WSO2 ESB
• MulBthreaded and asynchronous message processing core
• Based on a number of well known open source projects (eg:
Axis2, HXp Core)
• REpresentaBonal State Transfer
• An architectural Style – Not a Standard
• RESTful applicaBons use HTTP requests to • post data (create and/or update) • read data (e.g., make queries) • Delete data.
• REST uses HTTP for CRUD (Create/Read/Update/Delete) operaBons.
Eg: TwiXer REST API • hXps://dev.twiXer.com/docs/api/1.1
What is REST?
“How OrganizaBons thinks RESTFul Apps”
“Hang in There SOAP”
Moral of the Story…
• Replacing exisBng technologies is not easy • Every technology has its own strengths and weaknesses
– Despite its arcane terminology, the structured descripBon capabiliBes of the WSDL standard is being praised even by hard-‐core fans of REST
– No technology can be designated “universally superior”
REST API
• Exposing RESTful APIs • A easy way to expose exisBng SOAP services over REST
• REST à SOAP conversion • Mainly used in WSO2 API Manager
HTTP Based RESTful Interactions
IntegraBng RESTful ApplicaBons
Demo
REST APIs
l An API is similar to a web application hosted on the ESB
l Anchored at a specific URL path (context)
l /test l /dictionary l /foo/bar
l Can be bound to a specific host and a port l Contains one or more resources
Resources
l A RESTful resource exposed over HTTP l Similar to a proxy service but focuses on REST l Can be associated with
l A set of HTTP methods - GET only, GET and POST only, All HTTP
methods
l A specific content type - application/xml, application/json
l A particular class of clients (user agents)
Dispatching Requests to a Resource
l URL patterns l Reg-Ex match
l /test/* l Extension match
l *.jsp l Exact match
l /test/index.jsp
l URI templates l /dictionary/{character}/{word} l /accounts/{accountId}/{operation}
l HTTP Verbs (GET/PUT/POST/OPTIONS)
APIs and Resources
APIs and Resources
/people
APIs and Resources
/people
GET /staff/*
APIs and Resources
/people
GET /staff/*
POST /add/{name}
Resource Examples
API Example
API Demo: Coffee Shop
Coffee Shop: URL Schemes
l /order/{order-id} – GET, POST – Add/Update/View orders
l /orders/ – GET – Retrieve Pending Order List
Coffee Shop: Add Order
• POST /order/ <?xml version="1.0" encoding="UTF-8"?> <order> <drink>Caffe Misto</drink> </order> curl -v -d @order.xml -H "Content-type: application/xml" http://127.0.0.1:8281/order
Coffee Shop: Get Order
• GET /order/{order-id} curl –v http://127.0.0.1:8281/order/{order-id}
Coffee Shop: List Orders
• GET /orders/ curl -v http://127.0.0.1:8281/orders
API Demo: Coffee Shop
Complete Tutorial: http://bit.ly/PZz6RZ
HTTP Endpoint
• New in WSO2ESB 4.7.0 • Enhances RESTful support. Can be used with SOAP WS.
• Support for HTTP verbs and URI-Template variables
• An example: • Exposing Twitter Search API
OAuth: REST security done right
• Adheres to statelessness in REST architecture.
API Management Goals
l Service provider objecBves l Define APIs l Define security requirements and SLAs l Monitor API usage and SLAs
l Service consumer objecBves l Discover and browse APIs l Sign up and obtain API keys l Consume APIs using the obtained keys l Monitor API usage and SLAs
Engage with WSO2
• Helping you get the most out of your deployments • From project evaluation and inception to development
and going into production, WSO2 is your partner in ensuring 100% project success