OData (Open Data Protocol) queries are used to retrieve and manipulate data in RESTful APIs. Understanding the important keywords in an OData query helps optimize its functionality. Here are the most critical OData query keywords:
1. $filter
- Used to apply conditions on the data retrieved.
- Example:
?$filter=Age gt 30
- Operators:
- Comparison:
eq
,ne
,gt
,ge
,lt
,le
- Logical:
and
,or
,not
- String functions:
startswith
,endswith
,contains
- Comparison:
2. $select
- Used to specify which properties to include in the response, reducing the data payload.
- Example:
?$select=Name,Age
3. $expand
- Retrieves related entities in a single request (expanding navigation properties).
- Example:
?$expand=Orders
4. $orderby
- Specifies the order in which to sort the results.
- Example:
?$orderby=Name desc
5. $top
- Limits the number of results returned.
- Example:
?$top=5
6. $skip
- Skips the specified number of results, useful for pagination.
- Example:
?$skip=10
7. $count
- Returns the count of entities in the response.
- Example:
?$count=true
8. $format
- Specifies the format of the response (JSON, XML).
- Example:
?$format=json
9. $search
- Performs full-text search across all properties.
- Example:
?$search="John"
10. $inlinecount
- Allows including the count of records in the response.
- Example:
?$inlinecount=allpages
11. $apply
- Performs data aggregation (grouping, filtering, etc.).
- Example:
?$apply=groupby((Category), aggregate(Sales with sum as TotalSales))
No comments:
Post a Comment