# Requesting

OData services support requests for data via HTTP GET requests.

# Entity Collections

Requesting entity sets, and entities from the set, are the two most common OData requests:

GET http://localhost:8000/odata/People
1
{
  "@context": "http://127.0.0.1:8000/odata/$metadata#People",
  "value": [
    {
      "id": "michael-caine",
      "name": "Michael Caine"
    },
    {
      "id": "bob-hoskins",
      "name": "Bob Hoskins"
    }
  ]
}
1
2
3
4
5
6
7
8
9
10
11
12
13

OData URLs are case-sensitive, make sure you're using the right casing for your entity sets!

# Individual Entity by ID

The requests below return an individual entity of type Person by the given ID 'michael-caine'.

The first uses the standard OData syntax where the key is provided inside parentheses. The key must be provided as the correct type, in this case it is a string.

The second shows OData's key-as-segment convention, allowing the key to be provided as a path segment. The provided key is type-coerced into the correct format when this syntax is used.

GET http://localhost:8000/odata/People('michael-caine')
GET http://localhost:8000/odata/People/michael-caine
1
2
{
  "@context": "http://localhost:8000/odata/$metadata#People/$entity",
  "id": "michael-caine",
  "name": "Michael Caine"
}
1
2
3
4
5

# Individual Property

To address an entity property clients append a path segment containing property name to the URL of the entity. If the property has a complex type, properties of that value can be addressed by further property name composition. First let's take a look at how to get a simple property. The request below returns the Name property of a Person.

GET http://localhost:8000/odata/People/michael-caine/name
1
{
  "@context": "http://localhost:8000/odata/$metadata#People('michael-caine')/name",
  "value": "Michael Caine"
}
1
2
3
4

Then let's see how to get a property value of a complex type. The request below returns the Address of the complex type Location of a Person.

GET http://localhost:8000/odata/People/michael-caine/location/address
1
{
  "@context": "http://localhost:8000/odata/$metadata#People('michael-caine')/location/address",
  "value": "4 Hello Avenue"
}
1
2
3
4

# Individual Property Raw Value

To address the raw value of a primitive property, clients append a path segment containing the string $value to the property URL. The request below returns the raw value of property Name of a Person.

GET http://localhost:8000/odata/People/michael-caine/name/$value
1
Michael Caine
1