The Open Data Protocol
(OData)


Mike Taulty
Microsoft UK
mtaulty@microsoft.com
mtaulty.com
@mtaulty
RESTful services
client WLTM service for RESTful interactions




          client                  service
                                            3
                                                2
                                                    1
                                            resources
client WLTM service for RESTful interactions
        Application Code            Application Code          2
         Customer { ID = 2 }         Customer { ID = 2 }


        XML Client Stack            XML Server Stack

        BODY = <customer/>          BODY = <customer/>


      URI = http://service?id=2   URI = http://service?id=2


            VERB = POST
            STATUS = OK                 VERB = POST
                                        STATUS = OK

        HTTP Client Stack          HTTP Server Stack

             client                     service
key points involved here?

 1. HTTP       as the transport
               What’s so great about
 2. URI        that?indicates
    resource   1) Simplicity
 3. VERB       indicates action
               2) Low barrier to entry
 4. STATUS CODE3) Standardised
                         indicates
    outcome       technologies already
                  proven on the internet
 5. XML             as the
    payload(s)
ready to build?
       before you get to technologies

        1) URI scheme for addressing
           resources?
        2)someone must have (MVC) this
        WCF
           Can client compose done (REST)
       (REST)
               LINQ to
                 XML
                               additional
                              ASP.NET    WCF

           queries? already?
        3) XML payload format? JSON
        WebClient                    IIS
           as well?
        4) client payload format with
           Sharing                service
           clients?
        5) Including/linking to related
           data?
OData is a specification
OData


  builds on the RESTful fundamentals
          HTTP         XML         JSON


  to provide an open specification for
  exposing an abstract data model by adding
    URI addressing scheme
    payload using AtomPub, Atom and JSON
    metadata using the Entity Data Model
    batching mechanism for requests
it’s the usual “build or buy” trade-off


                                           standard
 •   productivity
 •   existing frameworks/libraries
 •   tooling support
 •   existing skillsets




                  custom             • full control
                                     • does what you want and
                                       no more
OData Basics
                            typed Entry
                                   property
     service                       property
                                  entries need to have a




                                        ...
           feed                   primary key
                                   property

                                        link
           feed




                                        ...
                                        link
                             all links are URI’s
               ...




                                   media link      BLOB
           feed
       service must publish a service document
                               typed Entry
         operation JSON listing top level feeds
       in AtomPub or              ...
               ...




        operation           typed Entry
demo
quick exploration of an OData service
OData URIs and Querying

         http://odata.netflix.com/Catalog/ Genres(‘Action Classics’)/Titles ? $orderby=R

                                   resource path                    query options


                                                                          $orderby (asc, desc )

 Collection              /Genres                                          $top

 Entry                   /Genres(‘Action Classics’)                       $skip

 Entry Property          /Genres(‘Action Classics’)/Name                  $filter

 Entry Property (text)   /Genres(‘Action Classics’)/Name/$value           $expand

 Cardinality             /Genres/$count                                   $format (*)

 Navigation              /Genres(‘Action Classics’)/Titles                $select

 Navigation Links        /Genres(‘Action Classics’)/$links/Titles         $inlinecount

 Service Operation       /ServiceOp?param1=‘val1’                         $ - some custom option
filters

        Logic       Arithmetic        String          Date/Time
 eq             add              contains      second
 ne             sub              endswith      hour
 gt             mul              startswith    minute
 gteq           div              length        day
 lt             mod
                                 indexof       month
 lteq           round
                                 insert        year
 and            floor
 or             ceiling          remove x 2
                                                        Type
 not                             replace
                                               isof
                                 substring
                                               cast
                                 tolower
                                 toupper
                                 trim
                                 concat
demo
querying OData services
service metadata

   an odata service can offer metadata
   describing the service
     greatly facilitates building clients
   service description is represented using
   the Entity Data Model (EDM)
     fully docmented in the specification
   Visual Studio (e.g.) supports this metadata
   format via “Add Service Reference”
demo
accessing service metadata
( including http://bit.ly/odataVisualizer )
operations

             specification also deals with



                   INVOKE
                   GET
                   DELETE
                    POST
                     PUT
         client                service
         client                service
                  maintaining links
   including MIME types for ATOM/JSON
                 maintaining linkshere
                including creating links
            MERGE also applicable
          concurrency checking lists
             including partial via ETags
        concurrency checkingvia ETags
         including protocol versioning
             tunnelling over POST
               tunnelling over POST
batching

      optimise round trips to the server
           be more “transactional”
            GET /Titles

            GET /People
                                RESPONSE
            POST /People(‘Tom Cruise’)
                          (multipart MIME)



           client                            service
                                POST
                          (multipart MIME)    $Batch
specification ->
 implementation
OData on the server
Custom via WCF Data Services
SharePoint 2010
SQL Azure
Azure Table Storage
SQL Reporting Services
IBM WebSphere
WCF Data Services                                                                                           IDataServiceMetadataProvider
( ADO.NET Data Services or ‘Astoria’ )                                                                      IDataServiceQueryProvider
                                                                                               Custom
                                                                                                            IDataServiceUpdateProvider
                                       config                                                  Provider
                                       •       AcceptCountRequests                                                        Custom Data
                                                                                                            IDataServiceStreamProvider
                                       •       AcceptProjectionRequests
                                                                                                            IDataServicePagingProvider defined )
                                                                                                                   ( dynamically
                                       •       MaxProtocolVersion
                                       •       MaxBatchCount
                                       •       MaxChangesetCount
                                       •       MaxExpandDepth
                                       •       MaxObjectCountOnInsert
                                       •       MaxResultsPerCollection
                                       •       EntitySetAccessRule
                    Host (IIS or self-hosted)
                                       •       EntitySetPageSize
                                       •       ServiceOperationAccessRule                                               Custom Object
                              WCF DataService                                                  Reflection                   Model
                                                                                               Provider +
                                                                                              IUpdatable
                                              Update
                                              Query




                                                                         Service Operations                               LINQ to SQL
                                                                                                                             Model
                               Interceptors




                                                           Entity Sets




                                                                                                 Entity
                                                                                              Framework
                                                                                               Provider
                                                                                                                      Entity Framework
                                                                                                                            Model
demo
building an OData service
OData on the client
.NET – desktop, server, Silverlight, Windows Phone 7
Javascript
iPhone (Objective C)
Java
PHP
Ruby
demo
building an OData client
more?




         www.odata.org
     or to see the website in odata
    services.odata.org/website/odata.svc
© 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.

Mike Taulty OData (NxtGen User Group UK)

  • 1.
    The Open DataProtocol (OData) Mike Taulty Microsoft UK mtaulty@microsoft.com mtaulty.com @mtaulty
  • 2.
  • 3.
    client WLTM servicefor RESTful interactions client service 3 2 1 resources
  • 4.
    client WLTM servicefor RESTful interactions Application Code Application Code 2 Customer { ID = 2 } Customer { ID = 2 } XML Client Stack XML Server Stack BODY = <customer/> BODY = <customer/> URI = http://service?id=2 URI = http://service?id=2 VERB = POST STATUS = OK VERB = POST STATUS = OK HTTP Client Stack HTTP Server Stack client service
  • 5.
    key points involvedhere? 1. HTTP as the transport What’s so great about 2. URI that?indicates resource 1) Simplicity 3. VERB indicates action 2) Low barrier to entry 4. STATUS CODE3) Standardised indicates outcome technologies already proven on the internet 5. XML as the payload(s)
  • 6.
    ready to build? before you get to technologies 1) URI scheme for addressing resources? 2)someone must have (MVC) this WCF Can client compose done (REST) (REST) LINQ to XML additional ASP.NET WCF queries? already? 3) XML payload format? JSON WebClient IIS as well? 4) client payload format with Sharing service clients? 5) Including/linking to related data?
  • 7.
    OData is aspecification
  • 8.
    OData buildson the RESTful fundamentals HTTP XML JSON to provide an open specification for exposing an abstract data model by adding URI addressing scheme payload using AtomPub, Atom and JSON metadata using the Entity Data Model batching mechanism for requests
  • 9.
    it’s the usual“build or buy” trade-off standard • productivity • existing frameworks/libraries • tooling support • existing skillsets custom • full control • does what you want and no more
  • 10.
    OData Basics typed Entry property service property entries need to have a ... feed primary key property link feed ... link all links are URI’s ... media link BLOB feed service must publish a service document typed Entry operation JSON listing top level feeds in AtomPub or ... ... operation typed Entry
  • 11.
    demo quick exploration ofan OData service
  • 12.
    OData URIs andQuerying http://odata.netflix.com/Catalog/ Genres(‘Action Classics’)/Titles ? $orderby=R resource path query options $orderby (asc, desc ) Collection /Genres $top Entry /Genres(‘Action Classics’) $skip Entry Property /Genres(‘Action Classics’)/Name $filter Entry Property (text) /Genres(‘Action Classics’)/Name/$value $expand Cardinality /Genres/$count $format (*) Navigation /Genres(‘Action Classics’)/Titles $select Navigation Links /Genres(‘Action Classics’)/$links/Titles $inlinecount Service Operation /ServiceOp?param1=‘val1’ $ - some custom option
  • 13.
    filters Logic Arithmetic String Date/Time eq add contains second ne sub endswith hour gt mul startswith minute gteq div length day lt mod indexof month lteq round insert year and floor or ceiling remove x 2 Type not replace isof substring cast tolower toupper trim concat
  • 14.
  • 15.
    service metadata an odata service can offer metadata describing the service greatly facilitates building clients service description is represented using the Entity Data Model (EDM) fully docmented in the specification Visual Studio (e.g.) supports this metadata format via “Add Service Reference”
  • 16.
    demo accessing service metadata (including http://bit.ly/odataVisualizer )
  • 17.
    operations specification also deals with INVOKE GET DELETE POST PUT client service client service maintaining links including MIME types for ATOM/JSON maintaining linkshere including creating links MERGE also applicable concurrency checking lists including partial via ETags concurrency checkingvia ETags including protocol versioning tunnelling over POST tunnelling over POST
  • 18.
    batching optimise round trips to the server be more “transactional” GET /Titles GET /People RESPONSE POST /People(‘Tom Cruise’) (multipart MIME) client service POST (multipart MIME) $Batch
  • 19.
  • 20.
    OData on theserver Custom via WCF Data Services SharePoint 2010 SQL Azure Azure Table Storage SQL Reporting Services IBM WebSphere
  • 21.
    WCF Data Services IDataServiceMetadataProvider ( ADO.NET Data Services or ‘Astoria’ ) IDataServiceQueryProvider Custom IDataServiceUpdateProvider config Provider • AcceptCountRequests Custom Data IDataServiceStreamProvider • AcceptProjectionRequests IDataServicePagingProvider defined ) ( dynamically • MaxProtocolVersion • MaxBatchCount • MaxChangesetCount • MaxExpandDepth • MaxObjectCountOnInsert • MaxResultsPerCollection • EntitySetAccessRule Host (IIS or self-hosted) • EntitySetPageSize • ServiceOperationAccessRule Custom Object WCF DataService Reflection Model Provider + IUpdatable Update Query Service Operations LINQ to SQL Model Interceptors Entity Sets Entity Framework Provider Entity Framework Model
  • 22.
  • 23.
    OData on theclient .NET – desktop, server, Silverlight, Windows Phone 7 Javascript iPhone (Objective C) Java PHP Ruby
  • 24.
  • 25.
    more? www.odata.org or to see the website in odata services.odata.org/website/odata.svc
  • 26.
    © 2010 MicrosoftCorporation. 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.