REST - What's It All About? (SAP TechEd 2012, CD110)

67
REST – So What’s It All About? CD110 @ SAP TechEd 2012 Las Vegas

description

 

Transcript of REST - What's It All About? (SAP TechEd 2012, CD110)

Page 1: REST - What's It All About? (SAP TechEd 2012, CD110)

REST – So What’s It All About?

CD110 @ SAP TechEd 2012 Las Vegas

Page 2: REST - What's It All About? (SAP TechEd 2012, CD110)

About Me

Sascha Wenninger

Integration Guy: SOA, PI, etc.

Drawer of Diagrams, Writer of Emails

@sufw

Page 3: REST - What's It All About? (SAP TechEd 2012, CD110)

Agenda

Concepts   Applica.ons  in  SAP-­‐land   Demo  

Page 4: REST - What's It All About? (SAP TechEd 2012, CD110)

Agenda

Concepts   Applica.ons  in  SAP-­‐land   Demo  

Page 5: REST - What's It All About? (SAP TechEd 2012, CD110)

REST

Page 6: REST - What's It All About? (SAP TechEd 2012, CD110)

REpresentational State Transfer

Page 7: REST - What's It All About? (SAP TechEd 2012, CD110)

What Does That Mean?

Page 8: REST - What's It All About? (SAP TechEd 2012, CD110)

The Client communicates with the Server

by modifying the state of Resources

through Representations

Page 9: REST - What's It All About? (SAP TechEd 2012, CD110)

It’s  the  Web    

(for  machines)  

Page 10: REST - What's It All About? (SAP TechEd 2012, CD110)

REST  interfaces  manipulate  the  state  of  resources  “Process  as  a  state  machine/data  flow  diagram”  Resource-­‐oriented  decomposi.on  of  business  processes  

   

SOA-­‐style  interfaces  perform  a  specific  task  “Process  as  a  flowchart/workflow”  Func.onal  decomposi.on  of  business  processes  

Page 11: REST - What's It All About? (SAP TechEd 2012, CD110)

Representations?

The server can store its data in whatever way it likes The client is unaware of this, and can store the same things

differently Each party serialises its internal state into Representations This provides loose coupling!

Page 12: REST - What's It All About? (SAP TechEd 2012, CD110)

Everything has a URL

Page 13: REST - What's It All About? (SAP TechEd 2012, CD110)

URLs because everyone understands them: http://saperp.BlueT.com.au/customer/12345

URLs are cheap. Use lots of them! http://api.netflix.com/catalog/titles/movies/60021896 http://api.netflix.com/catalog/titles/movies/60021896/cast http://api.netflix.com/catalog/titles/movies/60021896/synopsis

Page 14: REST - What's It All About? (SAP TechEd 2012, CD110)

Why the http:// URLs?

Page 15: REST - What's It All About? (SAP TechEd 2012, CD110)

HTTP is an Application Protocol.

REST recognises this.

Page 16: REST - What's It All About? (SAP TechEd 2012, CD110)

But How is that Better than SOAP?

Page 17: REST - What's It All About? (SAP TechEd 2012, CD110)

Remember the OSI Stack?

Layer   Example  7   Applica/on   DNS,  FTP,  HTTP,  etc.  6   Presenta.on   SSL  5   Session   L2TP,  PPTP  4   Transport   TCP  3   Network   IP  2   Data  Link   PPP,  ARP  1   Physical   IEEE  802.11  

Page 18: REST - What's It All About? (SAP TechEd 2012, CD110)

SOAP was designed to be transport-protocol agnostic

Page 19: REST - What's It All About? (SAP TechEd 2012, CD110)

Many bindings for SOAP:

HTTP SMTP JMS

AMQP

Page 20: REST - What's It All About? (SAP TechEd 2012, CD110)

Many bindings for SOAP:

HTTP SMTP JMS

AMQP

Page 21: REST - What's It All About? (SAP TechEd 2012, CD110)

REST recognises this.

HTTP  is  an  Applica.on  Protocol.  

Page 22: REST - What's It All About? (SAP TechEd 2012, CD110)

SOAP knows nothing about it!

Page 23: REST - What's It All About? (SAP TechEd 2012, CD110)

So What?

Well, there are benefits to knowing…

Page 24: REST - What's It All About? (SAP TechEd 2012, CD110)

Reliable Communication (as long as the client knows how to

handle errors and retries)

Free* Caching! *provided by commodity infrastructure!

Page 25: REST - What's It All About? (SAP TechEd 2012, CD110)

Easy Metadata exchange via HTTP Headers! Accept Content-Type If-Modified-Since Last-Modified

Page 26: REST - What's It All About? (SAP TechEd 2012, CD110)

…and last but not least…

A Universally-Understood Protocol!

Page 27: REST - What's It All About? (SAP TechEd 2012, CD110)

HTTP has Standard Verbs

GET PUT POST DELETE HEAD OPTIONS PATCH TRACE

Page 28: REST - What's It All About? (SAP TechEd 2012, CD110)

HTTP has Standard Verbs

Standard Meaning à Constraints = scope for

optimization Widely Implemented à Everybody knows how to behave

Page 29: REST - What's It All About? (SAP TechEd 2012, CD110)

SOAP Doesn’t.

getAccountCustomerByInternalId

searchCustomerByBasicData updateSalesProspectStatusByPartnerSalesRepresentativeBasicData_sync

And everything works via HTTP POST (i.e. it uses HTTP as the dumb transport)

Page 30: REST - What's It All About? (SAP TechEd 2012, CD110)

HTTP has Standard Responses

200 OK 302 Moved Permanently 404 Not Found 406 Method Not Allowed 409 Conflict 418 I’m a Teapot …

Page 31: REST - What's It All About? (SAP TechEd 2012, CD110)

SOAP Doesn’t.

Page 32: REST - What's It All About? (SAP TechEd 2012, CD110)

One last principle before we move on:

HATEOAS  

Page 33: REST - What's It All About? (SAP TechEd 2012, CD110)

One last principle before we move on:

Hypertext  As  The  Engine  Of  Applica.on  State  

Page 34: REST - What's It All About? (SAP TechEd 2012, CD110)

An Example Client requests Shopping Cart Server sends HTML page with items and links

Client’s move Client clicks the “Check Out” link Server sends HTML page with Total Amount

Client’s move Client clicks the “Pay” link Server sends HTML page with “Thank You” message

Page 35: REST - What's It All About? (SAP TechEd 2012, CD110)

Notice Something?

The Client is responsible for moving forward in a process The server guides the client forward

(with ‘Check Out’, ‘Pay’ links) The client is responsible for completing the process

If the client stops, the server doesn’t care!

Page 36: REST - What's It All About? (SAP TechEd 2012, CD110)

Notice Something?

The server doesn’t maintain session/application state. It does maintain resource state!

Every request modifies the state of a resource In the example, the client causes the state of the “Shopping

Cart” resource to be modified.

Page 37: REST - What's It All About? (SAP TechEd 2012, CD110)

Concepts   Applica.ons  in  SAP-­‐land   Demo  

Page 38: REST - What's It All About? (SAP TechEd 2012, CD110)

NetWeaver Gateway

Page 39: REST - What's It All About? (SAP TechEd 2012, CD110)

RESTful OData API

Add-On to NetWeaver 7.0*

Current version: 2.0 SP05

Strategic for SAP

Devices Enterprise Software

Web

SRM SCM ERP

PLM CRM

SAP  Business  Suite  

SAP  NetWeaver  Gateway  

Social

*see  Prerequisites  and  Deployment  Op.ons  

Page 40: REST - What's It All About? (SAP TechEd 2012, CD110)

The Good Things

•  Exposes BAPIs, RFCs & custom ABAP classes via OData XML –  Specific connectors for BOL (GenIL), HANA, BW, BOR, Workflow, etc.

•  Well integrated into SAP’s roadmap –  Tight integration with SUP 2.1+

–  Duet Enterprise uses Gateway internally

•  Framework provides flexible security and auditing/logging

•  Push notifications to consumers after subscription

•  Expose data & functionality from older (pre-7.0) systems

Page 41: REST - What's It All About? (SAP TechEd 2012, CD110)

New Since Last Year

•  JSON (finally! :-) •  Batch operations

•  “Deltas”, aka conditional requests •  “Model Composition”, aka Mash-ups

•  New Service Builder (SEGW)

•  Idempotency Support •  etc… (see What’s New)

Page 42: REST - What's It All About? (SAP TechEd 2012, CD110)

2 Approaches to Development

Generation Tools

•  Quickly expose BAPIs, RFCs and GUI screens

•  Up & running in minutes!

OData Channel

•  Complete Control •  Build custom code adhering to

a structured framework with a library of helper classes

•  Since SP04: SEGW

Page 43: REST - What's It All About? (SAP TechEd 2012, CD110)

2 Approaches to Development

Generation Tools

•  Quickly expose BAPIs, RFCs and GUI screens

•  Up & running in minutes!

OData Channel

•  Complete Control •  Build custom code adhering to

a structured framework with a library of helper classes

•  New tool SEGW since SP04

Page 44: REST - What's It All About? (SAP TechEd 2012, CD110)

The Limitations

•  Only supports OData (both XML & JSON) –  no custom representations (other XML/JSON, PDF, etc.)

•  Limited support for complex input parameters

•  Inherits the limitations of the backend services

Page 45: REST - What's It All About? (SAP TechEd 2012, CD110)

More Info on Gateway at TechEd

CD109 How the University of Mississippi Runs Better with NetWeaver Gateway

CD160 NetWeaver Gateway Development for Beginners

CD204 NetWeaver Gateway and OData in Detail

CD267 Developing Applications with HTML5 Toolkit and NetWeaver Gateway

MOB107 Best Practices for Establishing and Running a Mobile Landscape

MOB204 Building SAP Applications Using NetWeaver Gateway and HTML5

MOB205 From Start to Finish - Developing an iPad App Using NW Gateway

PMC206 NetWeaver PI and Gateway - When to Use What

TEC107 NetWeaver Gateway Overview - Roadmap and Strategy

Page 46: REST - What's It All About? (SAP TechEd 2012, CD110)

Custom Development

Page 47: REST - What's It All About? (SAP TechEd 2012, CD110)

DJ Adams Started It All!

Page 48: REST - What's It All About? (SAP TechEd 2012, CD110)

A Simple RESTful API for SAP CRM

•  BusinessPartners everywhere •  BPs have roles (e.g. Customer, Contact Person, Employee…) •  BPs have relationships with other BPs •  Relationships have attributes •  Relationships lead to Opportunities

Target consumer: Mobile app built with HTML5 + jQuery Mobile

Page 49: REST - What's It All About? (SAP TechEd 2012, CD110)

3 Resources

http://sapcrm:8000/api/businesspartner http://sapcrm:8000/api/bprelationship http://sapcrm:8000/api/opportunity plus any sub-resources we need

Page 50: REST - What's It All About? (SAP TechEd 2012, CD110)

Design Principles

JSON as the default format

Roles & Relationships via hyperlinks

Client must only know the ‘entry point’ URL to its own BP

All other client interaction driven by hyperlinks

There is a great ABAP ßà JSON library on CodeExchange!

Page 51: REST - What's It All About? (SAP TechEd 2012, CD110)

Sidebar: Hyperlinks in JSON

Page 52: REST - What's It All About? (SAP TechEd 2012, CD110)

Sidebar: Hyperlinks in JSON

No one standard to show hyperlinks à We chose the simplest option we found: “links”: {

“self”: “http://…”,

“up”: “http://…”,

“http://auspost.com.au/api/doc/rels/tracking”: “http://…”,

}

magic  keyword  rela.onship*  

custom  rela.onship   link  URL  

*as  per  IANA  standard  

Page 53: REST - What's It All About? (SAP TechEd 2012, CD110)

ICF Configuration in SAP CRM

Create  a  public  class    

Page 54: REST - What's It All About? (SAP TechEd 2012, CD110)

ICF Configuration in SAP CRM

Assign interface IF_HTTP_EXTENSION

Page 55: REST - What's It All About? (SAP TechEd 2012, CD110)

Insert Code Here…

Page 56: REST - What's It All About? (SAP TechEd 2012, CD110)
Page 57: REST - What's It All About? (SAP TechEd 2012, CD110)
Page 58: REST - What's It All About? (SAP TechEd 2012, CD110)
Page 59: REST - What's It All About? (SAP TechEd 2012, CD110)
Page 60: REST - What's It All About? (SAP TechEd 2012, CD110)

Demo

Page 61: REST - What's It All About? (SAP TechEd 2012, CD110)

Summary

•  REST is an architectural style –  Apply web principles to A2A integration –  Promotes true loose coupling via hyperlinks –  Based on Resources rather than functionality or tasks

•  NetWeaver Gateway can expose SAP data & functionality in a RESTful way.

•  More specific requirements can be met with Z code •  Most mobile frameworks rely on RESTful integration

–  But the REST style is equally valid for A2A and non-mobile scenarios!

Page 62: REST - What's It All About? (SAP TechEd 2012, CD110)

About Me

Sascha Wenninger [email protected] @sufw

Page 63: REST - What's It All About? (SAP TechEd 2012, CD110)

Get the Latest Version of this Talk!

http://slideshare.net/sufw

This  presenta.on  by  Sascha  Wenninger  is  available  under  a  Crea.ve  Commons  A`ribu.on-­‐ShareAlike  3.0  license  

Page 64: REST - What's It All About? (SAP TechEd 2012, CD110)

Feedback

Please complete a session evaluation for this session

Session Code: CD110

Page 65: REST - What's It All About? (SAP TechEd 2012, CD110)

Resources & Further Reading A free eBook on REST, by InfoQ: http://www.infoq.com/minibooks/emag-03-2010-rest Other interesting blogs and articles on InfoQ:

http://www.infoq.com/articles/RESTSOAFuture The Richardson Maturity Model, explained by Martin Fowler: http://martinfowler.com/articles/richardsonMaturityModel.html

...and by Leonard Richardson himself: http://www.crummy.com/writing/speaking/2008-QCon/act3.html DJ Adams’ original blog on REST on SCN:

http://scn.sap.com/people/dj.adams/blog/2004/06/24/forget-soap--build-real-web-services-with-the-icf Further blogs by DJ on implementing RESTful services via the ICF:

http://scn.sap.com/people/dj.adams/blog/2009/09/21/a-new-rest-handler-dispatcher-for-the-icf http://scn.sap.com/people/dj.adams/blog/2010/01/07/representational-state-transfer-rest-and-sap http://scn.sap.com/people/dj.adams/blog/2009/09/30/rest-orientation-controlling-access-to-resources

A Simple Intro to JSON: http://json.org CORS – Cross-Origin Resource Sharing, by the Mozilla Developer Network:

http://hacks.mozilla.org/2009/07/cross-site-xmlhttprequest-with-cors/

Page 66: REST - What's It All About? (SAP TechEd 2012, CD110)

Resources & Further Reading RESTful APIs from Scratch – Lessons Learnt (so far):

http://scn.sap.com/community/technology-innovation/blog/2012/06/03/restful-apis-from-scratch-lessons-learnt-so-far The NetWeaver Gateway space on SCN: http://scn.sap.com/community/netweaver-gateway HTTP: An Application-Level Protocol: http://dev.opera.com/articles/view/http-basic-introduction/ HTTP: Let’s GET It On!: http://dev.opera.com/articles/view/http-lets-get-it-on/ HTTP: Response Codes: http://dev.opera.com/articles/view/http-response-codes/ Resources are not Objects: http://ruben.verborgh.org/blog/2012/09/27/the-object-resource-impedance-mismatch/

(a good read for OO programmers) Known Limitations of SAP NetWeaver Gateway: SAP Note 1574568

Page 67: REST - What's It All About? (SAP TechEd 2012, CD110)

Attributions Images by Geek & Poke (Oliver Widder):

http://geekandpoke.typepad.com/.a/6a00d8341d3df553ef0133f3e30a99970b-pi http://geekandpoke.typepad.com/.a/6a00d8341d3df553ef0105362b2664970c-pi http://geekandpoke.typepad.com/.a/6a00d8341d3df553ef015390312d9f970b-pi

‘Standards’ by xkcd (Randall Munroe): http://xkcd.com/927/ ‘Permanent State’ by Gaping Void (Hugh MacLeod): http://gapingvoid.com/2011/07/28/permanent-state/ Many thanks to all for providing their work under a Creative Commons license! J