Upload
glen-gordon
View
127
Download
3
Tags:
Embed Size (px)
DESCRIPTION
An overview of OData delivered at the Atlanta iOS meetup 3/15/2011
Citation preview
OData: A primer for iOS developers
Glen GordonDeveloper EvangelistMicrosoft Corporationhttp://glengordon.name@glengordon
Who is this Microsoft guy?
• I support developer communities in GA, AL, MS• I work with developers from all roles: enterprise,
consultants, ISVs, students, startups, designers• Lots of ways to interface with something Microsoft
related– .NET, PHP, JavaScript– Silverlight, Windows Phone, iOS
• My goal is to make members of the community successful by introducing new technology or connecting people
Agenda
• The case for OData• A look at the format• Producers, services and consumers• Resources and tips
why data services?
break data silos
== data sharing & integration
Requirements for Web Data Services
• Web friendly, just plain HTTP• Uniform patterns• Focus on data, not on formats• Stay high level, abstract the store
business logic
store
service interface
data service != gateway to database
odata in 1 slide…
OData
• Uniform way of representing structured data– Atom, JSON formats
• Uniform URI conventions– Navigation, filtering, sorting, paging, etc.
• Uniform operations– Addressability– GET, POST, PUT, DELETE always mean the same
The name Atom applies to a pair of related standards. The Atom Syndication Format is an XML language used for web feeds, while the Atom Publishing Protocol (AtomPub) is a simple HTTP-based protocol for creating and updating web resources.
ATOMPub
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
What is a URI?
Full SQL like Query “Language”
HTTP Command (Verb) SQL Command
GET SELECT
PUT UPDATE
POST INSERT
DELETE DELETE
Entity-set /Bookmarks
Single entity /Bookmarks(123)
Member access /Bookmarks(123)/Name
Link traversal /Bookmarks(123)/Tags
Deep access /Bookmarks(123)/Tags('abc')/Name
Raw value access /Bookmarks(123)/Names/$value
Addressing entities and sets
Sorting /Bookmarks?$orderby=Name
Filtering /Bookmarks?$filter=Created gt '2007-05-07'
Paging /Bookmarks?$top=10&$skip=30
Inline expansion /Bookmarks?$expand=Tags
Presentation options
Query Option Description$expand Expand related data inline with the results, e.g. Categories/$expand=Products would expand Product
data inline with each Category entry.$filter A Boolean expression for whether a particular entry should be included in the feed, e.g. Categories?
$filter=CategoryName eq 'Produce'. The Query Expression section describes OData expressions.$format One of “atom” (the default), “json” or “xml” depending on how you’d like your data returned to you.$inlinecount Includes the number of entries without the filter applied as a count element on the feed itself, e.g.
Categories?$top=4&$inlinecount=allpages will return 8 with the default Northwind database installed.
$orderby One or more comma-separated expressions with an optional “asc” (the default) or “desc” depending on the order you’d like the values sorted, e.g. Categories?$orderby=CategoryName desc.
$select Limit the properties on each entry to just those requested, e.g. Categories?$select=CategoryName,Description.
$skip How many entries you’d like to skip, e.g. Categories?$skip=4.$skiptoken Skips entries up to one past the one that matches the unique key. Used for paged access into a feed.
Best used with $orderby, e.g. Categories?$orderby=CategoryID&$skiptoken=5 will skip everything ‘til it reaches the CategoryID of 5, then return entries past that.
$top Return entries from the top of the feed, e.g. Categories?$top=4
Query Options
Operation Example DescriptionGrouping (x add 4) eq 3 Used to make clear or override default operator precedence
(which I can never remember anyway).
Member access Categories(3)/Description Access of entity by ID or property by name.
Method call startswith(Description, “Bread”)
Call a built in method.
Negate -x Change numeric sign.Not not x Logical not.And x and y Conditional and.Or x or y Conditional or.Multiply x mul y Multiplication.Divide x div y Division.Modulo x mod y Remainder.Add x add y Addition.Subtract x sub y Subtraction.Less than x lt y Comparison.Greater than x gt y Comparison.Less than or equal x le y Comparison.Greater than or equal x ge y Comparison.Equals x eq y Comparison.Not equals x ne y Comparison.
Filter Expressions
Method Example Descriptionendswith endswith(x, 'foo') Whether the end of the first parameter value matches the second parameter
value.indexof indexof(x, 'foo') Index of the first occurrence of the second parameter value in the first
parameter value or -1 otherwise.replace replace(x, 'foo', 'bar') String value with all occurrences of the second parameter value replaced by
the third parameter value in the first parameter value.
startswith startswith(x, 'foo') Whether the beginning of the first parameter values matches the second parameter value.
tolower tolower(x) String value with the contents of the parameter value converted to lower case.
toupper toupper(x) String value with the contents of the parameter value converted to upper case.
trim trim(x) String value with the contents of the parameter value with all leading and trailing white-space characters removed.
substring substring(x)substring(x, y)
String value starting at the character index specified by the second parameter value in the first parameter string value.
substringof substringof(x)substringof(x, y)
Whether the second parameter string value occurs in the first parameter string value.
concat concat(x)concat(y)
String value which is the first and second parameter values merged together with the first parameter value coming first in the result.
length length(x) The number of characters in the specified parameter value.
Filter Methods
• Examples
http://services.odata.org/OData.svc/GetProductsByRating?rating=5
– Identifies the "GetProductsByRating" Service Operation and specifies a value of 5 for the "rating" input parameter.
Service Operations(Functions)
Producers and Consumers
OData Producers
• Windows Communication Foundation (WCF)• SharePoint 2010• IBM WebSphere• SQL Azure• Windows Azure Table Storage• SQL Server Reporting Services• Microsoft Dynamics CRM 2011• GeoREST• Build your own
OData Services
• ebay• Netflix• Twitpic• Windows Live• NerdDinner• Open Government Data Initiative• Open Science Data Initiative• Windows Azure Marketplace DataMarket
OData Consumers – End Users
• Web Browsers• Excel 2010• OData Explorer
OData Consumers – Client Libraries
• .NET• Javascript• PHP• Java• Windows Phone 7• iOS (Objective C)• Ruby• Joomla• Drupal
Servers• WCF Data Services• SharePoint 2010• SQL Server Reporting Services 2008 R2• SQL Azure• IBM WebSphere eXtreme Scale• Microsoft Media Room• WCF RIA Services
Services• Netflix• Mix 2010• Nerd Dinner• Vancouver’s vanGuide• Open Government Data Initiative• Open Science Data Initiative• Microsoft Codename “Dallas”• City of Edmonton
Clients• Excel + PowerPivot• LINQPad• OData Explorer
Client libraries• .NET• Silverlight• Windows Phone 7 Series• Javascript• Java• Objective-C• PHP
http://odata.org/producers
http://odata.org/consumers
OData and iOS
OData and iOS
• http requests• Parse XML or JSONOR• Use the OData Client for Objective-C• http://odataobjc.codeplex.com/
demos
Resources
• All things OData: http://odata.org
• Email: [email protected]• Blog: http://glengordon.name• Data @ MSDN: http://msdn.com/data
© 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.
The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions,
it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.