REST & OData
  Sanjay Patel
WHAT WILL BE COVERED

• What is REST?
• What is OData?
• OData Architecture Overview
• OData Producers ,Consumers and Live OData Services
• Configure SharePoint 2010 to work with OData / Tools
• Demo#1- CRUD Operations on SharePoint lists using
  Odata
• Demo#2 - Create List Items using jQuery
• Q & A?
REST - REPRESENTATIONAL STATE TRANSFER

REST is an architecture style NOT a standard but it uses
standards

REST is the Service on the Web


It uses HTTP protocol


It uses URI for resource identification (REST)

It provides Uniform Interface
WHAT IS ODATA?

It is a protocol based on web standards

It is used for querying and updating data

It uses HTTP protocol


It uses ATOM and JSON web message formats

It uses URI for resource identification (REST)

It provides filtering, sorting, paging etc. OOTB
UNIFORM OPERATIONS

 HTTP POST

 • CREATE Data in Data Source

 HTTP GET

 • RETERIVE Data from Data Source

 HTTP PUT

 • UPDATE Data in Data Source

 HTTP DELETE

 • DELETE Data in Data Source
UNIFORM REPRESENTATIONS OF DATA


                  Message
                  Format                      JSON for
                                              AJAX
        JSON                  ATOM            clients
    • Text based Format     • XML Based
    • Comes from              Format          ATOM for
      JavaScript world      • Originally
    • Can be consumed by      competed with   any type
      many languages          RSS
    • Same as ATOM with
      less <> and more []
                            • Boils down to
                              lists of data
                                              of clients
WHAT PROBLEM ODATA IS TRYING TO SOLVE?




• What is the common problem? - Scattered data all over in different data sources and
  not a common way to access them

• The Solution is OData – It defines a common approach to access diverse data
HOW ODATA WORKS?




• OData Data Model – Provides a way to structure data, uses EDM same as Microsoft
  Entity Framework
• OData Service – Implements OData protocol, It also provides abstractions of the OData
  data model to translate data between its underlying form
• OData Protocol – Set of RESTful interactions like CRUD operations using Odata defined
  query language
• OData Client Library – Makes life easy for developers by providing them a way to access
  data via the OData protocol
UNIFORM URI CONVENTIONS/DEMO
System     Descriptions                               Examples
Query
Options
$filter    Applies the filtering condition            http://services.odata.org/Northwind/Northwind.svc/Cus
                                                      tomers?$filter=substringof('Alfreds', CompanyName) eq
                                                      true
$top       Returns top number of data items           http://services.odata.org/OData/OData.svc/Products?$t
                                                      op=5
$skip      Skips specified number of data items       http://services.odata.org/OData/OData.svc/Categories(1
                                                      )/Products?$skip=2
$orderby   Sort data items                            http://services.odata.org/OData/OData.svc/Products?$o
                                                      rderby=Rating
$expand    Request set of related entities to be      http://services.odata.org/OData/OData.svc/Categories?$
           retrieved                                  expand=Products
$select    Select specified properties only for the   http://services.odata.org/OData/OData.svc/Products?$s
           data items                                 elect=Price,Name
$count     Returns the total count of all data        http://services.odata.org/OData/OData.svc/Categories(1
           items                                      )/Products/$count
$format    Request data in the specified format       http://services.odata.org/OData/OData.svc/Products?$f
                                                      ormat=atom
UNIFORM URI CONVENTIONS (CONTINUE…)
Operators     Descriptions       Examples

Eq            Equal              http://services.odata.org/Northwind/Northwind.svc/Suppliers?$filter =
                                 City eq 'London'
Ne            Not equal          http://services.odata.org/Northwind/Northwind.svc/Suppliers?$filter =
                                 City ne 'London'
Gt            Greater than       http://services.odata.org/Northwind/Northwind.svc/Products?$filter =
                                 UnitPrice gt 10
Ge            Greater than or    http://services.odata.org/Northwind/Northwind.svc/Products?$filter =
              equal              UnitPrice ge 20
Lt            Less than          http://services.odata.org/Northwind/Northwind.svc/Products?$filter =
                                 UnitPrice lt 20
Le            Less than or       http://services.odata.org/Northwind/Northwind.svc/Products?$filter =
              equal              UnitPrice le 10
And           Logical and        http://services.odata.org/Northwind/Northwind.svc/Products?$filter =
                                 UnitPrice le 10 and UnitsInStock gt 10
Or            Logical or         http://services.odata.org/Northwind/Northwind.svc/Products?$filter =
                                 UnitPrice le 10 or UnitsInStock gt 10
Not           Logical negation   http://services.odata.org/Northwind/Northwind.svc/Products?$filter =
                                 not startswith(ProductName,'Ch')
ODATA Producers and Consumers



         PRODUCER                     CONSUMER



 SharePoint 2010, IBM Web         Browsers , ODATA Explorer ,
Sphere , SSRS, Windows Azure     Excel 2010 , LINQPAD, Sesame
      table storage etc.                 OData Browser




        Live OData Services: Netflix, OGDI,
        Pluralsight, TechEd2010, NerdDinner
        More details: http://www.odata.org/ecosystem
CONFIGURE SHAREPOINT 2010 WITH ODATA / TOOLS

• Install ADO.NET Data Services (CTP 2) to avoid 404 Errors -
  http://www.microsoft.com/download/en/details.aspx?id=23113
• Where is your Data Service Endpoint? –
  http://<sitename>/_vti_bin/ListData.svc
• Install Open Data Protocol Visualizer -
  http://visualstudiogallery.msdn.microsoft.com/f4ac856a-796e-4d78-9a3d-
  0120d8137722/
• Fiddler2 (Web debugging tool) – http://www.fiddler2.com/fiddler2/
• cURL (Command line tool for CRUD operations using OData) -
  http://curl.haxx.se/
DEMO – LET’S SEE ODATA WORKING IN SHAREPOINT 2010!



                       • CRUD Operations on
          Demo#1         SharePoint lists using OData




          Demo#2       • Create List Items using jQuery
Thanks a lot!
                            Q&A

Contact Information:
http://www.neudesic.com
Sanjay.Patel@neudesic.com
http://sanjaypatelblogs.wordpress.com/
http://www.linkedin.com/pub/sanjay-patel/4/82/16a
   @sanjay18283
OData and SharePoint

OData and SharePoint

  • 1.
    REST & OData Sanjay Patel
  • 2.
    WHAT WILL BECOVERED • What is REST? • What is OData? • OData Architecture Overview • OData Producers ,Consumers and Live OData Services • Configure SharePoint 2010 to work with OData / Tools • Demo#1- CRUD Operations on SharePoint lists using Odata • Demo#2 - Create List Items using jQuery • Q & A?
  • 3.
    REST - REPRESENTATIONALSTATE TRANSFER REST is an architecture style NOT a standard but it uses standards REST is the Service on the Web It uses HTTP protocol It uses URI for resource identification (REST) It provides Uniform Interface
  • 4.
    WHAT IS ODATA? Itis a protocol based on web standards It is used for querying and updating data It uses HTTP protocol It uses ATOM and JSON web message formats It uses URI for resource identification (REST) It provides filtering, sorting, paging etc. OOTB
  • 5.
    UNIFORM OPERATIONS HTTPPOST • CREATE Data in Data Source HTTP GET • RETERIVE Data from Data Source HTTP PUT • UPDATE Data in Data Source HTTP DELETE • DELETE Data in Data Source
  • 6.
    UNIFORM REPRESENTATIONS OFDATA Message Format JSON for AJAX JSON ATOM clients • Text based Format • XML Based • Comes from Format ATOM for JavaScript world • Originally • Can be consumed by competed with any type many languages RSS • Same as ATOM with less <> and more [] • Boils down to lists of data of clients
  • 7.
    WHAT PROBLEM ODATAIS TRYING TO SOLVE? • What is the common problem? - Scattered data all over in different data sources and not a common way to access them • The Solution is OData – It defines a common approach to access diverse data
  • 8.
    HOW ODATA WORKS? •OData Data Model – Provides a way to structure data, uses EDM same as Microsoft Entity Framework • OData Service – Implements OData protocol, It also provides abstractions of the OData data model to translate data between its underlying form • OData Protocol – Set of RESTful interactions like CRUD operations using Odata defined query language • OData Client Library – Makes life easy for developers by providing them a way to access data via the OData protocol
  • 9.
    UNIFORM URI CONVENTIONS/DEMO System Descriptions Examples Query Options $filter Applies the filtering condition http://services.odata.org/Northwind/Northwind.svc/Cus tomers?$filter=substringof('Alfreds', CompanyName) eq true $top Returns top number of data items http://services.odata.org/OData/OData.svc/Products?$t op=5 $skip Skips specified number of data items http://services.odata.org/OData/OData.svc/Categories(1 )/Products?$skip=2 $orderby Sort data items http://services.odata.org/OData/OData.svc/Products?$o rderby=Rating $expand Request set of related entities to be http://services.odata.org/OData/OData.svc/Categories?$ retrieved expand=Products $select Select specified properties only for the http://services.odata.org/OData/OData.svc/Products?$s data items elect=Price,Name $count Returns the total count of all data http://services.odata.org/OData/OData.svc/Categories(1 items )/Products/$count $format Request data in the specified format http://services.odata.org/OData/OData.svc/Products?$f ormat=atom
  • 10.
    UNIFORM URI CONVENTIONS(CONTINUE…) Operators Descriptions Examples Eq Equal http://services.odata.org/Northwind/Northwind.svc/Suppliers?$filter = City eq 'London' Ne Not equal http://services.odata.org/Northwind/Northwind.svc/Suppliers?$filter = City ne 'London' Gt Greater than http://services.odata.org/Northwind/Northwind.svc/Products?$filter = UnitPrice gt 10 Ge Greater than or http://services.odata.org/Northwind/Northwind.svc/Products?$filter = equal UnitPrice ge 20 Lt Less than http://services.odata.org/Northwind/Northwind.svc/Products?$filter = UnitPrice lt 20 Le Less than or http://services.odata.org/Northwind/Northwind.svc/Products?$filter = equal UnitPrice le 10 And Logical and http://services.odata.org/Northwind/Northwind.svc/Products?$filter = UnitPrice le 10 and UnitsInStock gt 10 Or Logical or http://services.odata.org/Northwind/Northwind.svc/Products?$filter = UnitPrice le 10 or UnitsInStock gt 10 Not Logical negation http://services.odata.org/Northwind/Northwind.svc/Products?$filter = not startswith(ProductName,'Ch')
  • 11.
    ODATA Producers andConsumers PRODUCER CONSUMER SharePoint 2010, IBM Web Browsers , ODATA Explorer , Sphere , SSRS, Windows Azure Excel 2010 , LINQPAD, Sesame table storage etc. OData Browser Live OData Services: Netflix, OGDI, Pluralsight, TechEd2010, NerdDinner More details: http://www.odata.org/ecosystem
  • 12.
    CONFIGURE SHAREPOINT 2010WITH ODATA / TOOLS • Install ADO.NET Data Services (CTP 2) to avoid 404 Errors - http://www.microsoft.com/download/en/details.aspx?id=23113 • Where is your Data Service Endpoint? – http://<sitename>/_vti_bin/ListData.svc • Install Open Data Protocol Visualizer - http://visualstudiogallery.msdn.microsoft.com/f4ac856a-796e-4d78-9a3d- 0120d8137722/ • Fiddler2 (Web debugging tool) – http://www.fiddler2.com/fiddler2/ • cURL (Command line tool for CRUD operations using OData) - http://curl.haxx.se/
  • 13.
    DEMO – LET’SSEE ODATA WORKING IN SHAREPOINT 2010! • CRUD Operations on Demo#1 SharePoint lists using OData Demo#2 • Create List Items using jQuery
  • 14.
    Thanks a lot! Q&A Contact Information: http://www.neudesic.com Sanjay.Patel@neudesic.com http://sanjaypatelblogs.wordpress.com/ http://www.linkedin.com/pub/sanjay-patel/4/82/16a @sanjay18283