odata

16
1 Presentation on OData

Upload: monalisa-patel

Post on 14-Apr-2017

307 views

Category:

Technology


3 download

TRANSCRIPT

Page 1: Odata

1

Presentation on OData

Page 2: Odata

2

What is OData

• Open Data Protocol (OData) is an open protocol for sharing data.• It is built upon AtomPub, itself an extension of Atom Publishing Protocol.

[The Atom Publishing Protocol (AtomPub) is an Application level protocol for publishing and editing web resources.]

• OData is based on REST (Representational State Transfer) ; therefore a simple web browser can view the data exposed through an OData service.

• The basic idea behind OData is to use a well known data format (Atom feed) to expose a list of entities.

• AtomPub extends the basic Atom Protocol by allowing not only read but the whole set of CRUD operations.

Page 3: Odata

3

• Atom is an XML-based document format that describes Collections of related

• information known as "feeds". Feeds are composed of a number of items, known as Entries.

Page 4: Odata

4

How OData Works: Technology Basics

• The OData technology has four main parts:1. OData data model2. OData protocol3. OData client libraries4. OData service

Page 5: Odata

5

1. The OData data model, which provides a generic way to organize and describe data.

2. The OData protocol, which lets a client make requests to and get responses from an OData service. Those interactions include the usual create/read/update/delete (CRUD) operations, along with an OData-defined query language.

3. OData client libraries, which make it easier to create software that accesses data via the OData protocol. Because OData relies on REST, using an OData-specific client library isn't strictly required. But most OData clients are applications, and so providing pre-built libraries for making OData requests and getting results makes life simpler for the developers who create those applications.

4. An OData service, which exposes an endpoint that allows access to data. This service implements the OData protocol, and it also uses the abstractions of the OData data model to translate data between its underlying form, which might be relational tables, SharePoint lists, or something else, into the format sent to the client.

Page 6: Odata

6

Consumption of Odata Example

1. Requesting resources : Foe example here we use the service of an open trip management system .

If a person named Russell White, who has formerly registered TripPin, would like to find out who are the other people in it.

GET http://services.odata.org/v4/TripPinServiceRW/People HTTP/1.1 OData-Version: 4.0 OData-MaxVersion: 4.0 This uses version 4 TripPin from where it fetch data List of people whose data are retrieved HTTP Version 1.1

Page 7: Odata

7

In Response• HTTP/1.1 200 OK• Content-Length: 1007• Content-Type: application/json; odata.metadata=minimal Service Route URL Resource path • OData-Version: 4.0• { • "@odata.context":"http://services.odata.org/V4/(S(fo3by51qwd1q124ngi2rxrzc))/TripPinServiceRW/$metadata#People",• "@odata.nextLink":"http://services.odata.org/V4/(S(fo3by51qwd1q124ngi2rxrzc))/TripPinServiceRW/People?%24skiptoken=8",• "value":[ • { • "@odata.id":"http://services.odata.org/V4/(S(fo3by51qwd1q124ngi2rxrzc))/TripPinServiceRW/People('russellwhyte')",• "@odata.etag":"W/\"08D285C0E2748213\"",• "@odata.editLink":"http://services.odata.org/V4/(S(fo3by51qwd1q124ngi2rxrzc))/TripPinServiceRW/People('russellwhyte')",• "UserName":"russellwhyte",• "FirstName":"Russell",• "LastName":"Whyte",• "Emails":[ • "[email protected]",• "[email protected]"• ],• "AddressInfo":[ • { • "Address":"187 Suffolk Ln.",• "City":{ • "CountryRegion":"United States",• "Name":"Boise",• "Region":"ID"• }• }• ],• "Gender":"Male",• "Concurrency":635717560892162579• },• {• ......................................• }• ]}

Page 8: Odata

8

2. Requesting an individual resource

GET http://services.odata.org/v4/TripPinServiceRW/People('russellwhyte') HTTP/1.1OData-Version: 4.0 User name of the individualOData-MaxVersion: 4.0 Resource

3. Queries

GET http://services.odata.org/v4/TripPinServiceRW/People?$top=2 & $select=FirstName, LastName & $filter=Trips/any(d:d/Budget gt 3000) HTTP/1.1OData-Version: 4.0OData-MaxVersion: 4.0

Page 9: Odata

9

In Response• HTTP/1.1 200 OK• Content-Length: 367• Content-Type: application/json; odata.metadata=minimal• OData-Version: 4.0• { • "@odata.context":"http://services.odata.org/V4/(S(fo3by51qwd1q124ngi2rxrzc))/TripPinServiceRW/

$metadata#People(FirstName,LastName)",• "value":[ • { • "@odata.id":"http://services.odata.org/V4/(S(fo3by51qwd1q124ngi2rxrzc))/TripPinServiceRW/People('scottketchum')",• "@odata.etag":"W/\"08D285C0E2748213\"",• "@odata.editLink":"http://services.odata.org/V4/(S(fo3by51qwd1q124ngi2rxrzc))/TripPinServiceRW/

People('scottketchum')",• "FirstName":"Scott",• "LastName":"Ketchum"• },• { • "@odata.id":"http://services.odata.org/V4/(S(fo3by51qwd1q124ngi2rxrzc))/TripPinServiceRW/People('ronaldmundy')",• "@odata.etag":"W/\"08D285C0E2748213\"",• "@odata.editLink":"http://services.odata.org/V4/(S(fo3by51qwd1q124ngi2rxrzc))/TripPinServiceRW/

People('ronaldmundy')",• "FirstName":"Ronald",• "LastName":"Mundy"• }• ]• }

Page 10: Odata

10

4. Creating a new resourcePOST http://services.odata.org/v4/(S(34wtn2c0hkuk5ekg0pjr513b))/TripPinServiceRW/People HTTP/1.1OData-Version: 4.0OData-MaxVersion: 4.0Content-Length: 428Content-Type: application/json{ "UserName":"lewisblack", "FirstName":"Lewis", "LastName":"Black", "Emails":[ "[email protected]" ], "AddressInfo":[ { "Address":"187 Suffolk Ln.", "City":{ "CountryRegion":"United States", "Name":"Boise", "Region":"ID" } } ], "Gender":"Male", "Concurrency":635519729375200400}

Page 11: Odata

11

In Response

HTTP/1.1 201 CreatedContent-Length: 652Content-Type: application/json;odata.metadata=minimal;odata.streaming=true;IEEE754Compatible=false;charset=utf-8ETag: W/'08D1D3800FC572E3'Location: http://services.odata.org/V4/(S(34wtn2c0hkuk5ekg0pjr513b))/TripPinServiceRW/People('lewisblack')OData-Version: 4.0

NOTE :- IEEE754Compatible=false ;= means that Int64(Represents a 64-bit signed integer.) and Decimal are serialized as numbers.

Page 12: Odata

12

5. Relating resourcesIn RESTful APIs, resources are usually dependent with each other. For that, the concept of relationships in OData can be defined among resources to add flexibility and richness to the data model.

Example -POST http://services.odata.org/v4/(S(34wtn2c0hkuk5ekg0pjr513b))/TripPinServiceRW/People('lewisblack')/Trips/$ref HTTP/1.1OData-Version: 4.0OData-MaxVersion: 4.0Content-Length: 123Content-Type: application/json{ "@odata.id":"http://services.odata.org/V4/(S(34wtn2c0hkuk5ekg0pjr513b))/TripPinServiceRW/People('russellwhyte')/Trips(0)"}

Page 13: Odata

13

In Response

HTTP/1.1 204 No ContentOData-Version: 4.0

6. Invoking a FunctionOData supports defining functions and actions to represent complicated logic and which can be frequently used.

For Example :- After having explored the TripPin OData service, Russell finds out that it has a function called GetInvolvedPeople from which he can find out the involved people of a specific trip.

Page 14: Odata

14

GET http://services.odata.org/v4/(S(34wtn2c0hkuk5ekg0pjr513b))/TripPinServiceRW/People('russellwhyte')/Trips(0)/Microsoft.OData.SampleService.Models.TripPin.GetInvolvedPeople()HTTP/1.1OData-Version: 4.0OData-MaxVersion: 4.0

In Response :HTTP/1.1 200 OKContent-Length: 582Content-Type: application/json; odata.metadata=minimalOData-Version: 4.0{ "@odata.context":"http://services.odata.org/V4/(S(fo3by51qwd1q124ngi2rxrzc))/TripPinServiceRW/$metadata#People","value":[ { "@odata.id":"http://services.odata.org/V4/(S(fo3by51qwd1q124ngi2rxrzc))/TripPinServiceRW/People('russellwhyte')", "@odata.etag":"W/\"08D285C4BEF5EC5D\"", "@odata.editLink":"http://services.odata.org/V4/(S(fo3by51qwd1q124ngi2rxrzc))/TripPinServiceRW/People('russellwhyte')",

Page 15: Odata

15

• "UserName":"russellwhyte",• "FirstName":"Russell",• "LastName":"Whyte",• "Emails":[ • "[email protected]",• "[email protected]"• ],• "AddressInfo":[ • { • "Address":"187 Suffolk Ln.",• "City":{ • "CountryRegion":"United States",• "Name":"Boise",• "Region":"ID"• }• }• ],• "Gender":"Male",• "Concurrency":635717577476533341• },• { • "@odata.id":"http://services.odata.org/V4/(S(fo3by51qwd1q124ngi2rxrzc))/TripPinServiceRW/People('scottketchum')",• "@odata.etag":"W/\"08D285C4BEF5EC5D\"",• "@odata.editLink":"http://services.odata.org/V4/(S(fo3by51qwd1q124ngi2rxrzc))/TripPinServiceRW/People('scottketchum')",• "UserName":"scottketchum",• "FirstName":"Scott",• "LastName":"Ketchum",• "Emails":[ • "[email protected]"• ],• "AddressInfo":[ • { • "Address":"2817 Milton Dr.",• "City":{ • "CountryRegion":"United States",• "Name":"Albuquerque",• "Region":"NM"• }• }• ],• "Gender":"Male",• "Concurrency":635717577476533341• }• ] }

Page 16: Odata

16