Top Banner
Gaining the Knowledge of the Open Data Protocol (OData) Chris Woodruff Director, Perficient Level: Intermediate
44

Gaining the Knowledge of the Open Data Protocol (OData)

Jan 27, 2015

Download

Technology

Chris Woodruff

The Open Data Protocol (OData) is an open protocol for sharing data. It provides a way to break down data silos and increase the shared value of data by creating an ecosystem in which data consumers can interoperate with data producers in a way that is far more powerful than currently possible, enabling more applications to make sense of a broader set of data. Every producer and consumer of data that participates in this ecosystem increases its overall value. OData is consistent with the way the Web works – it makes a deep commitment to URIs for resource identification and commits to an HTTP-based, uniform interface for interacting with those resources (just like the Web). This commitment to core Web principles allows OData to enable a new level of data integration and interoperability across a broad range of clients, servers, services, and tools.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Gaining the Knowledge of the Open Data Protocol (OData)

Gaining the Knowledge of the Open Data Protocol (OData)

Chris WoodruffDirector, Perficient

Level: Intermediate

Page 2: Gaining the Knowledge of the Open Data Protocol (OData)

Who I am?

Chris Woodruff

MVP, Visual C#

Director at Perficient

Co-host of Deep Fried Bytes Podcast

@cwoodruff / [email protected] / Skype: cwoodruff

Page 3: Gaining the Knowledge of the Open Data Protocol (OData)

You will learn:

• Understand the background of OData• Have an understanding of the OData

protocol• How to produce an OData feed using

WCF Data Services• How to produce an OData feed using

ASP.NET Web API• How to consume an OData feed using

LINQ

Page 4: Gaining the Knowledge of the Open Data Protocol (OData)

BACKGROUNDKnowledge of OData

Page 5: Gaining the Knowledge of the Open Data Protocol (OData)

Today, the tools for capturing data both at the mega-scale and at the milli-scale are just dreadful. After you have captured the data, you need to curate it before you can start doing any kind of data analysis, and we lack good tools for both data curation and data analysis.

Jim Gray

Quote

Page 6: Gaining the Knowledge of the Open Data Protocol (OData)

Problem: Data APIs frequently create more problems than solutionsTHIS TALK IS ABOUT ONE SOLUTION.

Page 7: Gaining the Knowledge of the Open Data Protocol (OData)

Survey

…knows what the web is

…are comfortable w/ HTTP and XML? JSON?

…have a basic understanding of the term REST

…have created a Data API

Page 8: Gaining the Knowledge of the Open Data Protocol (OData)

Is there really a problem?What is it?QUIZ TIME

Page 9: Gaining the Knowledge of the Open Data Protocol (OData)

Facebook: What fields will I get when I read a post?

Page 10: Gaining the Knowledge of the Open Data Protocol (OData)

Facebook: How do you like a post?

Page 11: Gaining the Knowledge of the Open Data Protocol (OData)

How do developers know what to do?

SO GIVEN THAT NOBODY KNEW THE ANSWERS TO THESE QUESTIONS,

Page 12: Gaining the Knowledge of the Open Data Protocol (OData)

I guess they use docs

Page 13: Gaining the Knowledge of the Open Data Protocol (OData)

So is there really a problem?YesDEVELOPERS DON’T HAVE TIME TO ACTUALLY READ THE DOCS

Page 14: Gaining the Knowledge of the Open Data Protocol (OData)

Can OData Magically cure the problem? No, but it can help.LET’S SEE HOW

Page 15: Gaining the Knowledge of the Open Data Protocol (OData)

THE PROTOCOLKnowledge of OData

Page 16: Gaining the Knowledge of the Open Data Protocol (OData)

The Basics of OData

Feeds, which are Collections of typed Entities

OData services can expose Actions and Functions (v4), Services (v3)

OData services expose all these constructs via URIs

OData service may also expose a Service Metadata Document

Page 17: Gaining the Knowledge of the Open Data Protocol (OData)

Full SQL like Query “Language”

HTTP Command (Verb)

SQL Command

GET SELECT

PUT UPDATE

POST INSERT

DELETE DELETE

Page 18: Gaining the Knowledge of the Open Data Protocol (OData)

The $metadata endpoint

Page 19: Gaining the Knowledge of the Open Data Protocol (OData)

URL Conventions

http://services.odata.org/OData/OData.svc

\_______________________________________/

|

service root URI

http://services.odata.org/OData/OData.svc/Category(1)/Products?$top=2&$orderby=name

\_______________________________________/ \__________________/ \_________________/

| | |

service root URI resource path query options

Page 20: Gaining the Knowledge of the Open Data Protocol (OData)

URL Conventions

$filter/Suppliers?$filter=Address/City eq 'Redmond‘

$orderby/Products?$orderby=ReleaseDate asc, Rating desc

$top and $skip/Products?$top=5&$skip=2

$select and $expand/Products?$select=*,Category/Name&$expand=Category

Page 21: Gaining the Knowledge of the Open Data Protocol (OData)

Combining UEL Conventions

• http://.../Players/–?$skip=10–&$top=2–&filter=substringof(‘Wood',nameLast)–&$orderby=nameLast%20desc–&$select=nickname,yearBorn,nameFirst–&$format=json

Page 22: Gaining the Knowledge of the Open Data Protocol (OData)

Payload Conventions

• Success and error Codes– 200 OK, 201 Created, 415 Unsupported Media Type,

etc

• Overall Format– JSON– AtomPub– JSON Verbose

• Nuances– PATCH, Null payloads, etc

Page 23: Gaining the Knowledge of the Open Data Protocol (OData)

JSON Format

• Friendly to Javascript• 90% more compact than AtomPub• Reads like a custom API• Very little OData “gunk”

Page 24: Gaining the Knowledge of the Open Data Protocol (OData)

Atom Format

• Atom parsers exist in many frameworks• Element fields can be mapped to their

Atom counterparts• A good example of OData interoperability

Page 25: Gaining the Knowledge of the Open Data Protocol (OData)

What else can you do with OData?

• Actions and Functions allow hypermedia-based method calls (non-CRUD operations)

• Defined conventions for PATCH and deep insert

• Vocabularies

Page 26: Gaining the Knowledge of the Open Data Protocol (OData)

OData isn’t always the best fit

• OData may not be a good fit for highly opinionated APIs laden with developer intent

• OData may not be a good fit for bulk data transfer

• OData may not be a good fit for the APIs that dramatically different in shape than the backend

Page 27: Gaining the Knowledge of the Open Data Protocol (OData)

OData does not support all queries

• OData doesn’t currently support aggregation– You can’t ask for customers that have at least 2

orders

• OData doesn’t currently support filters expansions– You can’t ask for a customer and only their orders

placed in 2013

• OData doesn't support “graph” queries– You can ask friend-of-a-friend type queries, but there

are limitations

Page 28: Gaining the Knowledge of the Open Data Protocol (OData)

OData is becoming a standard

• OASIS, ISO• ETA early 2014

Page 29: Gaining the Knowledge of the Open Data Protocol (OData)

Who uses OData?

Page 30: Gaining the Knowledge of the Open Data Protocol (OData)

What does OData give me and my organization?

Empower Internal Power Users

Empower Existing and Future Customers

Monetize Data for untapped Revenue

Page 31: Gaining the Knowledge of the Open Data Protocol (OData)

CREATING FEED W/ WCF DATA SERVICES

Knowledge of OData

Page 32: Gaining the Knowledge of the Open Data Protocol (OData)

WCF DATA SERVICESDEMO

Page 33: Gaining the Knowledge of the Open Data Protocol (OData)

CREATING FEED W/ ASP.NET WEB API

Knowledge of OData

Page 34: Gaining the Knowledge of the Open Data Protocol (OData)

ASP.NET WEB APIDEMO

Page 35: Gaining the Knowledge of the Open Data Protocol (OData)

OData Best Practices (Producer)

• Always design your OData feed will server-side paging if your entity collections hold large amounts of data.

• Looks at server-side validation of queries and data updates based on the user credentials sent through HTTP

Page 36: Gaining the Knowledge of the Open Data Protocol (OData)

CONSUMING ODATAKnowledge of OData

Page 37: Gaining the Knowledge of the Open Data Protocol (OData)

What if Data API’s were like…

LINQ?• What are the last 50 invoices we sent?

– context.Invoice.OrderByDescending(i=>i.PostedAt).Take(50);

• What are the invoices from the last 24 hours?– context.Invoice.Where(i=>i.PostedAt > DateTime.Now.AddDays(-1));

• How many $1M invoices have we sent?– context.Invoice.Where(i=>i.TotalAmount >= 1000000);

Page 38: Gaining the Knowledge of the Open Data Protocol (OData)

CONSUMING ODATA WITH LINQ

DEMO

Page 39: Gaining the Knowledge of the Open Data Protocol (OData)

OData Best Practices (Consumer)

• Use Query Projection to only bring back the entity properties you or your app needs.

• Think about client-side paging even if their exists server-side paging.

• Design and implement a client-side data caching function in your app (unless sensitive data).

Page 40: Gaining the Knowledge of the Open Data Protocol (OData)

Why are we excited!!

Page 41: Gaining the Knowledge of the Open Data Protocol (OData)

WRAP-UPKnowledge of OData

Page 42: Gaining the Knowledge of the Open Data Protocol (OData)

The demo projects can be found at:

github.com/cwoodruff/

Page 43: Gaining the Knowledge of the Open Data Protocol (OData)

Resources

RESThttp://www.ics.uci.edu/~taylor/documents/2002-REST-TOIT.pdf

OData

http://odata.org

http://odataprimer.com

Page 44: Gaining the Knowledge of the Open Data Protocol (OData)

Contact Me

Chris “Woody” [email protected]

Twitter @cwoodruff

Skype cwoodruff

http://chriswoodruff.com

http://deepfriedbytes.com