REST APIs for partners. What's the catch when applying best practices?
REST: So What's It All About? (SAP TechEd 2011, MOB107)
-
Upload
sascha-wenninger -
Category
Technology
-
view
6.576 -
download
4
description
Transcript of REST: So What's It All About? (SAP TechEd 2011, MOB107)
REST – So What’s It All About?
MOB107 @ SAP TechEd 2011Las Vegas
Agenda
Concepts Applications in SAP-land Demo
Agenda
Concepts Applications in SAP-land Demo
REST
REpresentationalStateTransfer
What Does That Mean?
The Client communicates with the Server
by modifying the state of Resources
through Representations
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!
Everything has a URL
URLs Identify Resources
REST interfaces manipulate the state of resources“Process as a state machine/data flow diagram”Resource-oriented decomposition of business processes
SOA-style interfaces perform a specific task“Process as a flowchart/workflow”Functional decomposition of business processes
HTTP is an Application Protocol.
REST recognises this.
Remember the OSI Stack?
Layer Example7 Application DNS, FTP, HTTP, etc.6 Presentation SSL5 Session L2TP, PPTP4 Transport TCP3 Network IP2 Data Link PPP, ARP1 Physical IEEE 802.11
This has a number of benefits…
Reliable Communication(as long as the client knows how to
handle errors and retries)
Free* Caching!
*provided by commodity infrastructure!
Easy Metadata exchange via HTTP Headers!
AcceptContent-TypeIf-Modified-SinceLast-Modified
…and last but not least…
A Universally-Understood Protocol!
But How is that Better than SOAP?
HTTP has Standard Verbs
GETPUTPOSTDELETEHEADOPTIONSPATCHTRACE
SOAP Doesn’t.
getAccountCustomerByInternalId
searchCustomerByBasicData
updateSalesProspectStatusByPartnerSalesRepresentativeBasicData_sync
And everything works via HTTP POST(i.e. it uses HTTP as the dumb transport)
HTTP has Standard Responses
200 OK302 Moved Permanently404 Not Found406 Method Not Allowed409 Conflict418 I’m a Teapot…
SOAP Doesn’t.
One last principle before we move on:
HATEOAS
One last principle before we move on:
HypertextAsTheEngineOfApplicationState
An Example
Client requests Shopping Cart
Server sends HTML page with items and linksClient’s move
Client clicks the “Check Out” link
Server sends HTML page with Total AmountClient’s move
Client clicks the “Pay” link
Server sends HTML page with “Thank You” message
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 processIf the client stops, the server doesn’t care!
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.
Concepts Applications in SAP-land Demo
NetWeaver Gateway
The Good Things
• Exposes BAPIs, RFCs & custom ABAP classes via OData XML
• Well integrated into SAP’s roadmap– Tight integration with v2.1 of SUP – Sybase Unwired Platform
– Duet Enterprise
– Standard content and pre-built integration will be delivered by SAP
• Framework provides flexible security and auditing/logging
• Push notifications to consumers after subscription
• Expose data & functionality from older (pre-7.02) systems
2 Approaches to Development
Generation Tools
• Quickly expose BAPIs, RFCs and GUI screens
• Up & running in minutes!
OData Channel
• Complete Control• Allows custom code adhering
to a structured framework with a library ofhelper classes
The Limitations
• Only supports OData (Open, but Microsoft-centric XML)– no custom representations (other XML, JSON, PDF, etc.)*
• Limited support for complex input parameters*
• The Generation tools don’t:– Allow modification of HTTP headers for caching, CORS, etc.
– Created linked resources (e.g. navigate Customer Order Item)
• Use of the OData Channel when developing Gateway Services makes this possible!
*In developmentCORS is a method for working around browser-based cross-domain scripting
security measures which can hamper JSON or AJAX-based browser applications.
Mapping to a BAPI
BAPI Field Defaults OData XML Field
More Info on Gateway at TechEd
CD164 SAP NetWeaver Gateway Basics
CD263 Developing and Consuming OData Services Using SAP NetWeaver Gateway
CD264 SAP and Microsoft: Building Apps for Both Worlds Using Duet Enterprise and Gateway
MOB130 Enabling Business Suite with SAP NetWeaver Gateway, example Sybase Unwired Platform
MOB230 Developing Simple Mobile Applications Using OData for SAP
MOB265 Building a Mobile App using Sybase Unwired Platform with OData via SAP NetWeaver Gateway
Custom Development
DJ Adams Started It All!
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
3 Resources
http://sapcrm:8000/auspost/businesspartner
http://sapcrm:8000/auspost/bprelationship
http://sapcrm:8000/auspost/opportunity
plus any sub-resources we need
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!
Sidebar: Hyperlinks in JSON
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 keywordrelationship*
custom relationship link URL
*as per IANA standard
ICF Configuration in SAP CRM
Create a public class
ICF Configuration in SAP CRM
Assign interface IF_HTTP_EXTENSION
Insert Code Here…
Demo
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!
Feedback
Please complete a session evaluation for this session
Session Code: MOB107