30
OData: A primer for iOS developers Glen Gordon Developer Evangelist Microsoft Corporation http://glengordon.name @glengordon

OData for iOS developers

Embed Size (px)

DESCRIPTION

An overview of OData delivered at the Atlanta iOS meetup 3/15/2011

Citation preview

Page 1: OData for iOS developers

OData: A primer for iOS developers

Glen GordonDeveloper EvangelistMicrosoft Corporationhttp://glengordon.name@glengordon

Page 2: OData for iOS developers

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

Page 3: OData for iOS developers

Agenda

• The case for OData• A look at the format• Producers, services and consumers• Resources and tips

Page 4: OData for iOS developers

why data services?

Page 5: OData for iOS developers

break data silos

Page 6: OData for iOS developers

== data sharing & integration

Page 7: OData for iOS developers

Requirements for Web Data Services

• Web friendly, just plain HTTP• Uniform patterns• Focus on data, not on formats• Stay high level, abstract the store

Page 8: OData for iOS developers

business logic

store

service interface

data service != gateway to database

Page 9: OData for iOS developers

odata in 1 slide…

Page 10: OData for iOS developers

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

Page 11: OData for iOS developers

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

Page 12: OData for iOS developers

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?

Page 13: OData for iOS developers

Full SQL like Query “Language”

HTTP Command (Verb) SQL Command

GET SELECT

PUT UPDATE

POST INSERT

DELETE DELETE

Page 14: OData for iOS developers

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

Page 15: OData for iOS developers

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

Page 16: OData for iOS developers

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

Page 17: OData for iOS developers

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

Page 18: OData for iOS developers

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

Page 19: OData for iOS developers

• 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)

Page 20: OData for iOS developers

Producers and Consumers

Page 21: OData for iOS developers

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

Page 22: OData for iOS developers

OData Services

• ebay• Netflix• Twitpic• Windows Live• NerdDinner• Open Government Data Initiative• Open Science Data Initiative• Windows Azure Marketplace DataMarket

Page 23: OData for iOS developers

OData Consumers – End Users

• Web Browsers• Excel 2010• OData Explorer

Page 24: OData for iOS developers

OData Consumers – Client Libraries

• .NET• Javascript• PHP• Java• Windows Phone 7• iOS (Objective C)• Ruby• Joomla• Drupal

Page 25: OData for iOS developers

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

Page 26: OData for iOS developers

OData and iOS

Page 27: OData for iOS developers

OData and iOS

• http requests• Parse XML or JSONOR• Use the OData Client for Objective-C• http://odataobjc.codeplex.com/

Page 28: OData for iOS developers

demos

Page 29: OData for iOS developers

Resources

• All things OData: http://odata.org

• Email: [email protected]• Blog: http://glengordon.name• Data @ MSDN: http://msdn.com/data

Page 30: OData for iOS developers

© 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.