REST: So What's It All About? (SAP TechEd 2011, MOB107)

53
REST – So What’s It All About? MOB107 @ SAP TechEd 2011 Las Vegas

description

Google and Twitter have been using it for years and now SAP has joined in with Project Gateway. So what is REST all about, how is it different from SOA-style integration and what could you use it for? This presentation will give you an overview of the concepts which define the REST architectural style and what has made it so popular with Internet companies and long-haired developers. You will also get some pointers on how to implement RESTful services in your SAP systems and expose your SAP systems to Web and mobile applications - both with and without Project Gateway! And to see all this in action, SAP Mentor John Moy will demo how a mobile Web application using jQuery Mobile can consume a RESTful service built in ABAP!

Transcript of REST: So What's It All About? (SAP TechEd 2011, MOB107)

Page 1: REST: So What's It All About? (SAP TechEd 2011, MOB107)

REST – So What’s It All About?

MOB107 @ SAP TechEd 2011Las Vegas

Page 2: REST: So What's It All About? (SAP TechEd 2011, MOB107)

Agenda

Concepts Applications in SAP-land Demo

Page 3: REST: So What's It All About? (SAP TechEd 2011, MOB107)

Agenda

Concepts Applications in SAP-land Demo

Page 4: REST: So What's It All About? (SAP TechEd 2011, MOB107)

REST

Page 5: REST: So What's It All About? (SAP TechEd 2011, MOB107)

REpresentationalStateTransfer

Page 6: REST: So What's It All About? (SAP TechEd 2011, MOB107)

What Does That Mean?

Page 7: REST: So What's It All About? (SAP TechEd 2011, MOB107)

The Client communicates with the Server

by modifying the state of Resources

through Representations

Page 8: REST: So What's It All About? (SAP TechEd 2011, MOB107)

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 9: REST: So What's It All About? (SAP TechEd 2011, MOB107)

Everything has a URL

Page 10: REST: So What's It All About? (SAP TechEd 2011, MOB107)

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

Page 11: REST: So What's It All About? (SAP TechEd 2011, MOB107)

HTTP is an Application Protocol.

REST recognises this.

Page 12: REST: So What's It All About? (SAP TechEd 2011, MOB107)

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

Page 13: REST: So What's It All About? (SAP TechEd 2011, MOB107)

This has a number of benefits…

Page 14: REST: So What's It All About? (SAP TechEd 2011, MOB107)

Reliable Communication(as long as the client knows how to

handle errors and retries)

Free* Caching!

*provided by commodity infrastructure!

Page 15: REST: So What's It All About? (SAP TechEd 2011, MOB107)

Easy Metadata exchange via HTTP Headers!

AcceptContent-TypeIf-Modified-SinceLast-Modified

Page 16: REST: So What's It All About? (SAP TechEd 2011, MOB107)

…and last but not least…

A Universally-Understood Protocol!

Page 17: REST: So What's It All About? (SAP TechEd 2011, MOB107)

But How is that Better than SOAP?

Page 18: REST: So What's It All About? (SAP TechEd 2011, MOB107)

HTTP has Standard Verbs

GETPUTPOSTDELETEHEADOPTIONSPATCHTRACE

Page 19: REST: So What's It All About? (SAP TechEd 2011, MOB107)

SOAP Doesn’t.

getAccountCustomerByInternalId

searchCustomerByBasicData

updateSalesProspectStatusByPartnerSalesRepresentativeBasicData_sync

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

Page 20: REST: So What's It All About? (SAP TechEd 2011, MOB107)

HTTP has Standard Responses

200 OK302 Moved Permanently404 Not Found406 Method Not Allowed409 Conflict418 I’m a Teapot…

Page 21: REST: So What's It All About? (SAP TechEd 2011, MOB107)

SOAP Doesn’t.

Page 22: REST: So What's It All About? (SAP TechEd 2011, MOB107)

One last principle before we move on:

HATEOAS

Page 23: REST: So What's It All About? (SAP TechEd 2011, MOB107)

One last principle before we move on:

HypertextAsTheEngineOfApplicationState

Page 24: REST: So What's It All About? (SAP TechEd 2011, MOB107)

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

Page 25: REST: So What's It All About? (SAP TechEd 2011, MOB107)

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!

Page 26: REST: So What's It All About? (SAP TechEd 2011, MOB107)

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 27: REST: So What's It All About? (SAP TechEd 2011, MOB107)

Concepts Applications in SAP-land Demo

Page 28: REST: So What's It All About? (SAP TechEd 2011, MOB107)

NetWeaver Gateway

Page 29: REST: So What's It All About? (SAP TechEd 2011, MOB107)

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

Page 30: REST: So What's It All About? (SAP TechEd 2011, MOB107)

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

Page 31: REST: So What's It All About? (SAP TechEd 2011, MOB107)

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.

Page 32: REST: So What's It All About? (SAP TechEd 2011, MOB107)

Mapping to a BAPI

BAPI Field Defaults OData XML Field

Page 33: REST: So What's It All About? (SAP TechEd 2011, MOB107)
Page 34: REST: So What's It All About? (SAP TechEd 2011, MOB107)
Page 35: REST: So What's It All About? (SAP TechEd 2011, MOB107)

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

Page 36: REST: So What's It All About? (SAP TechEd 2011, MOB107)

Custom Development

Page 37: REST: So What's It All About? (SAP TechEd 2011, MOB107)

DJ Adams Started It All!

Page 38: REST: So What's It All About? (SAP TechEd 2011, MOB107)

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 39: REST: So What's It All About? (SAP TechEd 2011, MOB107)

3 Resources

http://sapcrm:8000/auspost/businesspartner

http://sapcrm:8000/auspost/bprelationship

http://sapcrm:8000/auspost/opportunity

plus any sub-resources we need

Page 40: REST: So What's It All About? (SAP TechEd 2011, MOB107)

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 41: REST: So What's It All About? (SAP TechEd 2011, MOB107)

Sidebar: Hyperlinks in JSON

Page 42: REST: So What's It All About? (SAP TechEd 2011, MOB107)

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

Page 43: REST: So What's It All About? (SAP TechEd 2011, MOB107)

ICF Configuration in SAP CRM

Create a public class

Page 44: REST: So What's It All About? (SAP TechEd 2011, MOB107)

ICF Configuration in SAP CRM

Assign interface IF_HTTP_EXTENSION

Page 45: REST: So What's It All About? (SAP TechEd 2011, MOB107)

Insert Code Here…

Page 46: REST: So What's It All About? (SAP TechEd 2011, MOB107)
Page 47: REST: So What's It All About? (SAP TechEd 2011, MOB107)
Page 48: REST: So What's It All About? (SAP TechEd 2011, MOB107)
Page 49: REST: So What's It All About? (SAP TechEd 2011, MOB107)
Page 50: REST: So What's It All About? (SAP TechEd 2011, MOB107)

Demo

Page 51: REST: So What's It All About? (SAP TechEd 2011, MOB107)

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 52: REST: So What's It All About? (SAP TechEd 2011, MOB107)

About Us

Sascha [email protected]@sufw

John [email protected]@jhmoy

Page 53: REST: So What's It All About? (SAP TechEd 2011, MOB107)

Feedback

Please complete a session evaluation for this session

Session Code: MOB107