OData: Universal Data Solvent or Clunky Enterprise Goo? (GlueCon 2015)
-
Upload
pat-patterson -
Category
Software
-
view
447 -
download
0
Transcript of OData: Universal Data Solvent or Clunky Enterprise Goo? (GlueCon 2015)
Universal Data Solvent or Clunky Enterprise Goo?
Pat PattersonDeveloper Evangelist Architect,
Salesforce@metadaddy
RESTful APIs are GREAT!
$ curl -H 'X-PrettyPrint:1' \-H 'Authorization: Bearer ACCESS_TOKEN' \https://na1.salesforce.com/services/data/v31.0/sobjects/Account/001E0000002Jv2eIAC{ "Id" : "001E0000002Jv2eIAC”, "Name" : "Edge Communications", "AccountNumber" : "CD451796", …}
BUT…
• REST is a style, not a standard• RESTful, RESTlike, RESTish• URL parameters?– e.g. retrieve only a subset of properties
• Retrieve a set of records via a query?• Metadata– WADL?– RAML?– Swagger?
Enter… OData
“OData is a standardized protocol for creating and consuming data APIs.
OData builds on core protocols like HTTP and commonly accepted methodologies like REST.
The result is a uniform way to expose full-featured data APIs.”
www.odata.org
OData
• Proposed by Microsoft– 2009
• Standardized by OASIS– OData 4.0, 2014
OData
• URIs for resource identity
http://services.odata.org/V4/OData/OData.svc/Products
?$filter=Rating+eq+3&$select=Rating,+Name
7
OData System Query Options
• $search• $filter• $count• $orderby• $skip
• $top• $expand• $select• $format
OData
• HTTP transport– GET, POST, PUT/PATCH/MERGE, DELETE
GET /V4/OData/OData.svc/Products(1) HTTP/1.1Host: services.odata.org HTTP/1.1 200 OK...
OData• Atom XML/JSON representation
10
OData ExamplesLet’s play with curl!
OData Examples
$ curl 'http://services.odata.org/V4/OData/OData.svc/'{ "@odata.context": "http://services.odata.org/V4/OData/OData.svc/$metadata", "value": [ { "kind": "EntitySet", "name": "Products", "url": "Products" }, { "kind": "EntitySet", "name": "ProductDetails", "url": "ProductDetails" }, ...
Service Document (JSON)
OData Examples
$ curl 'http://services.odata.org/V4/OData/OData.svc/?$format=xml'<?xml version="1.0" encoding="utf-8"?><service xmlns="http://www.w3.org/2007/app" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:m="http://docs.oasis-open.org/odata/ns/metadata" xml:base="http://services.odata.org/V4/OData/OData.svc/" m:context="http://services.odata.org/V4/OData/OData.svc/$metadata"> <workspace> <atom:title type="text">Default</atom:title> <collection href="Products"> <atom:title type="text">Products</atom:title> </collection> <collection href="ProductDetails"> <atom:title type="text">ProductDetails</atom:title> </collection> ...
Service Document (XML)
OData Examples
$ curl 'http://services.odata.org/V4/OData/OData.svc/$metadata'<?xml version="1.0" encoding="utf-8"?><edmx:Edmx xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx" Version="4.0"> <edmx:DataServices> <Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="ODataDemo"> <EntityType Name="Product"> <Key> <PropertyRef Name="ID"/> </Key> <Property Name="ID" Type="Edm.Int32" Nullable="false"/> <Property Name="Name" Type="Edm.String"/> ...
Metadata (XML Only )
OData Examples
$ curl 'http://services.odata.org/V4/OData/OData.svc/Products?$filter=Rating+eq+3&$select=Rating,+Name'{ "@odata.context": "http://services.odata.org/V4/OData/OData.svc/$metadata#Products(Rating,Name)", "value": [ { "Name": "Milk", "Rating": 3 }, { "Name": "Vint soda", "Rating": 3 }, ...
Query
OData Examples
$ curl 'http://services.odata.org/V4/OData/OData.svc/Products(1)'{ "@odata.context": "http://services.odata.org/V4/OData/OData.svc/$metadata#Products/$entity", "ID": 1, "Name": "Milk", "Description": "Low fat milk", "ReleaseDate": "1995-10-01T00:00:00Z", "DiscontinuedDate": null, "Rating": 3, "Price": 3.5}
Get Individual Entity
OData Examples
$ curl -w "Status: %{http_code}\\n” \ -H 'Content-Type: application/json' \ -X PATCH \ -d '{"@odata.type":"ODataDemo.Product","Price":"2.99"}' \ 'http://services.odata.org/V4/OData/OData.svc/Products(1)’
Status: 204
Update Entity
OData Examples
$ curl -H 'Prefer: odata.track-changes' -H 'Prefer: odata.callback; url="https://myserver/cb?token=123"' 'http://services.odata.org/V4/OData/OData.svc/Products’
Server will POST notifications to the callback URL
Change Tracking
OData Adoption
•Microsoft• SAP• Salesforce• IBM• RedHat• Socrata
OData-Supporting Products
• Microsoft SQL Server• Windows Azure Active Directory• SAP NetWeaver• IBM WebSphere• JBoss Teiid• Salesforce1 Lightning Connect• Socrata Open Data Portal
OData Libraries
– Java– .Net– JavaScript– Objective-C– Python– Ruby– Node.js– PHP– C++
www.odata.org/libraries
OData Summary
• Standardizes data-centric web services• Exposes Data and Metadata• JSON or XML (Atom/AtomPub) representation over
HTTP• Wide industry support• Really not that clunky!
OData Resources
• OData– http://www.odata.org/
• Apache Olingo– http://olingo.apache.org/
Thank You!
Pat PattersonDeveloper Evangelist Architect, Salesforce@metadaddy