In this post, you will learn more about OData service URIs.
This is a post from a series Building OData Services. Earlier posts can be accessed at below links.
- Building OData Services  : OData Overview
- Building OData Services  : Understanding OData Service
- Building OData Services  : Create OData Service
- Building OData Services  : Register and Test OData Service
To work with OData it is very important to understand the URI options that can be used.
Summary of all URI Options
To demonstrate the options, Northwind service is used. This service was first introduced in OData Overview post where we looked at the metadata.
URL for the service : https://services.odata.org/V2/Northwind/Northwind.svc/
The below additions should be added after https://services.odata.org/V2/Northwind/Northwind.svc.
|Metadata||/$metadata||Shows metadata for the service|
|Get all records for the entity|
|Entity Set Count||/Customers/$count|
|Get count of records in a entity set|
|Get single entity record based on entity keys.For single key, it is not mandatory to mention the key name|
|Displays associated entity sets recordsNote , separated keys|
|In-lining||/Customers(‘ALFKI’)?$expand=Orders||Shows data for principal entity and associated entity together|
|Filter||/Customers?$filter=City eq ‘London’ and Country eq ‘UK’||Used to filter the entity set records based on any property|
|Search String||/Customers?search=’109′||Pass the search string which can be used to filter the data|
|Select||/Customers?$select=ContactName,City,Country||Select only specific fields|
|Filter and Select||/Customers?$filter=City eq ‘London’ &$select=ContactName,City,Country||To combine multiple options & can be used|
|Top and Skip||/Customers?$top=2&$skip=5||Top tells how many records to fetchSkip tells how many records to skip from the first recordTogether these help with displaying contents page by page|
/Customers?$orderby=Country desc,City asc
|Sorts the result by properties in Ascending (asc) or descending (desc) order. default is ascending|
|Function Import||/GetFlightNumbers?CarrierID=’AA’||GetCarrierFlights is name of the function import and Carrid is the importing parameter. ***This is an example and does not work with Northwind service.|
|$format=json||/Customers?$format=json||To get the data in json format|
Now, let us look at each URL more closely.
Shows metadata for the service. From the metadata you can understand the structure of the service. Metadata is a large document with information on all the Entity Types, Entity Sets, Associations etc.
Get all records for the entity.
Another URL that can be checked is – https://services.odata.org/V2/Northwind/Northwind.svc/Orders/
Entity Set Count
This gives number of records in entity set.
As this Entity Type has single field as a key, it is not needed to mention the key name.
Here, we need to mention the key names and values separated by comma (,) .
This means get all Orders for Customer entity with key ‘ALFKI’. This is one to many association.
This is one to one association where Product details for a product from the selected Order_Detail entity are shown.
Similarly rest of the URLs can be tested.
This is not available in Northwind service. This is an example created to depict how the function import is called. Here, GetFlightNumbers is the name of the Function Import and ‘AA’ is passed to the parameter CarrierID.
Next post – Building OData Services  : Implementing all URIs has all the information and code samples required for implementing these URIs.
Visit OData Development in SAP to explore all articles on OData.
If you like the content, please subscribe…