Download - WSO2 ESB Integration with REST

Transcript
Page 1: WSO2 ESB Integration with REST

WSO2 ESB Integration with REST

Dushan Abeyruwan Associate Tech Lead, Integration Tech Group

Ravi Undupitiya

Software Engineer, Integration Tech Group

Page 2: WSO2 ESB Integration with REST

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

Page 3: WSO2 ESB Integration with REST

150+ globally positioned support customers

Page 4: WSO2 ESB Integration with REST

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.  

 

Page 5: WSO2 ESB Integration with REST

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

Page 6: WSO2 ESB Integration with REST

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)  

Page 7: WSO2 ESB Integration with REST

 •     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?  

Page 8: WSO2 ESB Integration with REST

“How  OrganizaBons  thinks  RESTFul  Apps”  

Page 9: WSO2 ESB Integration with REST

“Hang  in  There  SOAP”  

Page 10: WSO2 ESB Integration with REST

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”  

 

Page 11: WSO2 ESB Integration with REST

REST API

•  Exposing  RESTful  APIs    • A  easy  way  to  expose  exisBng  SOAP  services  over  REST  

•  REST  à  SOAP  conversion  •  Mainly  used  in  WSO2  API  Manager      

Page 12: WSO2 ESB Integration with REST

HTTP Based RESTful Interactions

Page 13: WSO2 ESB Integration with REST

IntegraBng  RESTful  ApplicaBons  

Demo  

Page 14: WSO2 ESB Integration with REST

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

Page 15: WSO2 ESB Integration with REST

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)

Page 16: WSO2 ESB Integration with REST

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)

Page 17: WSO2 ESB Integration with REST

APIs and Resources

Page 18: WSO2 ESB Integration with REST

APIs and Resources

/people

Page 19: WSO2 ESB Integration with REST

APIs and Resources

/people

GET /staff/*

Page 20: WSO2 ESB Integration with REST

APIs and Resources

/people

GET /staff/*

POST /add/{name}

Page 21: WSO2 ESB Integration with REST

Resource Examples

Page 22: WSO2 ESB Integration with REST

API Example

Page 23: WSO2 ESB Integration with REST

API Demo: Coffee Shop

Page 24: WSO2 ESB Integration with REST

Coffee Shop: URL Schemes

l  /order/{order-id} – GET, POST – Add/Update/View orders

l  /orders/ – GET – Retrieve Pending Order List

Page 25: WSO2 ESB Integration with REST

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

Page 26: WSO2 ESB Integration with REST

Coffee Shop: Get Order

•  GET /order/{order-id} curl –v http://127.0.0.1:8281/order/{order-id}

Page 27: WSO2 ESB Integration with REST

Coffee Shop: List Orders

•  GET /orders/ curl -v http://127.0.0.1:8281/orders

Page 28: WSO2 ESB Integration with REST

API Demo: Coffee Shop

Complete Tutorial: http://bit.ly/PZz6RZ

Page 29: WSO2 ESB Integration with REST

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

Page 30: WSO2 ESB Integration with REST

OAuth: REST security done right

•  Adheres to statelessness in REST architecture.

Page 31: WSO2 ESB Integration with REST

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  

Page 32: WSO2 ESB Integration with REST

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