### Example 20: Canonical URL for previous example Source: https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html Shows the canonical URL for the same entity, omitting the key property name. ```http http://host/service/Products(1) ``` -------------------------------- ### Multipart batch response example (Example 104) Source: https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-protocol.html Example 104: multipart batch response referencing batch request example 101, assuming all requests except the final query succeed. Shows a 200 Ok multipart/mixed response with a boundary, a change set (cs_12u7hdkin252452345eknd_383673037) containing a 201 Created and a 204 No Content, and a final 404 Not Found error part. The response structure matches the request one-to-one except for change set failures and error termination. ```http HTTP/1.1 200 Ok OData-Version: 4.0 Content-Length: #### Content-Type: multipart/mixed; boundary=b_243234_25424_ef_892u748 --b_243234_25424_ef_892u748 Content-Type: application/http HTTP/1.1 200 Ok Content-Type: application/json Content-Length: ### --b_243234_25424_ef_892u748 Content-Type: multipart/mixed; boundary=cs_12u7hdkin252452345eknd_383673037 --cs_12u7hdkin252452345eknd_383673037 Content-Type: application/http Content-ID: 1 HTTP/1.1 201 Created Content-Type: application/json Location: http://host/service.svc/Customer('POIUY') Content-Length: ### --cs_12u7hdkin252452345eknd_383673037 Content-Type: application/http Content-ID: 2 HTTP/1.1 204 No Content Host: host --cs_12u7hdkin252452345eknd_383673037-- --b_243234_25424_ef_892u748 Content-Type: application/http HTTP/1.1 404 Not Found Content-Type: application/xml Content-Length: ### --b_243234_25424_ef_892u748— ``` -------------------------------- ### Example 47: $all with $search Source: https://docs.oasis-open.org/odata/odata/v4.01/os/part2-url-conventions/odata-v4.01-os-part2-url-conventions.html Example 47: all entities in a service that somehow match red. The $all resource is located at the service root and identifies the collection of all entities in a service. ```http http://host/service/$all?$search=red ``` -------------------------------- ### Example 101: Multipart batch request with change set Source: https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-protocol.html Example 101: a multipart batch request containing a query request, a change set with an insert (Content-ID=1) and an update (Content-ID=2), and a second query request. Request bodies are replaced with English descriptions inside <> brackets and OData-Version headers are omitted for brevity. The two empty lines after the Host header of the GET request are necessary: the first is part of the GET request header; the second is the empty body of the GET request, followed by a CRLF according to RFC2046. ```http POST /service/$batch HTTP/1.1 Host: host OData-Version: 4.0 Content-Type: multipart/mixed; boundary=batch_36522ad7-fc75-4b56-8c71-56071383e77b Content-Length: ### --batch_36522ad7-fc75-4b56-8c71-56071383e77b Content-Type: application/http GET /service/Customers('ALFKI') Host: host --batch_36522ad7-fc75-4b56-8c71-56071383e77b Content-Type: multipart/mixed; boundary=changeset_77162fcd-b8da-41ac-a9f8-9357efbbd --changeset_77162fcd-b8da-41ac-a9f8-9357efbbd Content-Type: application/http Content-ID: 1 POST /service/Customers HTTP/1.1 Host: host Content-Type: application/json Content-Length: ### --changeset_77162fcd-b8da-41ac-a9f8-9357efbbd Content-Type: application/http Content-ID: 2 PATCH /service/Customers('ALFKI') HTTP/1.1 Host: host Content-Type: application/json If-Match: xxxxx Prefer: return=minimal Content-Length: ### --changeset_77162fcd-b8da-41ac-a9f8-9357efbbd-- --batch_36522ad7-fc75-4b56-8c71-56071383e77b Content-Type: application/http GET /service/Products HTTP/1.1 Host: host --batch_36522ad7-fc75-4b56-8c71-56071383e77b-- ``` -------------------------------- ### Example 49: POST /$query with filter in body Source: https://docs.oasis-open.org/odata/odata/v4.01/os/part2-url-conventions/odata-v4.01-os-part2-url-conventions.html Example 49: passing a filter condition in the request body. The request uses POST to /$query with content-type text/plain and the query options in the body. ```http POST http://host/service/People/$query Content-Type: text/plain $filter=[FirstName,LastName]%20in%20[["John","Doe"],["Jane","Smith"]] ``` -------------------------------- ### Example 101: Batch request with query, change set, and second query Source: https://docs.oasis-open.org/odata/odata/v4.01/os/part1-protocol/odata-v4.01-os-part1-protocol.html Complete multipart batch request example showing the order: a query request, a change set with two operations (insert and update), and a second query request. The change set uses Content-ID headers and the batch boundary is batch_36522ad7-fc75-4b56-8c71-56071383e77b. Request bodies are omitted for brevity. ```HTTP POST /service/$batch HTTP/1.1 Host: host OData-Version: 4.0 Content-Type: multipart/mixed; boundary=batch_36522ad7-fc75-4b56-8c71-56071383e77b Content-Length: ### --batch_36522ad7-fc75-4b56-8c71-56071383e77b Content-Type: application/http GET /service/Customers('ALFKI') Host: host --batch_36522ad7-fc75-4b56-8c71-56071383e77b Content-Type: multipart/mixed; boundary=changeset_77162fcd-b8da-41ac-a9f8-9357efbbd --changeset_77162fcd-b8da-41ac-a9f8-9357efbbd Content-Type: application/http Content-ID: 1 POST /service/Customers HTTP/1.1 Host: host Content-Type: application/json Content-Length: ### --changeset_77162fcd-b8da-41ac-a9f8-9357efbbd Content-Type: application/http Content-ID: 2 PATCH /service/Customers('ALFKI') HTTP/1.1 Host: host Content-Type: application/json If-Match: xxxxx Prefer: return=minimal Content-Length: ### --changeset_77162fcd-b8da-41ac-a9f8-9357efbbd-- --batch_36522ad7-fc75-4b56-8c71-56071383e77b Content-Type: application/http GET /service/Products HTTP/1.1 Host: host --batch_36522ad7-fc75-4b56-8c71-56071383e77b-- ``` -------------------------------- ### Example 48: $all with type restriction and $filter Source: https://docs.oasis-open.org/odata/odata/v4.01/os/part2-url-conventions/odata-v4.01-os-part2-url-conventions.html Example 48: all Customer entities in a service whose name contains red. The $all resource is appended with the qualified entity type name Model.Customer to restrict the collection. ```http http://host/service/$all/Model.Customer?$filter=contains(Name,'red') ``` -------------------------------- ### Cross join response example Source: https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html Example response for the cross join query, showing the structure with navigation links for each joined entity set. ```json { "@odata.context":"http://host/service/$metadata#Collection(Edm.ComplexType)", "value":[ { "Products@odata.navigationLink":"Products(0)", "Sales@odata.navigationLink":"Sales(42)", }, { "Products@odata.navigationLink":"Products(0)", "Sales@odata.navigationLink":"Sales(57)", }, ... { "Products@odata.navigationLink":"Products(99)", "Sales@odata.navigationLink":"Sales(21)", } ] } ``` -------------------------------- ### Example 42: Combining two /$filter path segments Source: https://docs.oasis-open.org/odata/odata/v4.01/os/part2-url-conventions/odata-v4.01-os-part2-url-conventions.html Uses two /$filter path segments with parameter aliases to select red products costing less than 10. ```HTTP GET Products/$filter(@p)/$filter(@c)?@p=Price lt 10&@c=Color eq 'red' ``` -------------------------------- ### Invoke Bound Function with $it Prefix (Example 107) Source: https://docs.oasis-open.org/odata/odata/v4.01/os/part2-url-conventions/odata-v4.01-os-part2-url-conventions.html Example 107 from section 5.1.1.14.4 shows $it used as a path prefix to invoke a bound function overload on the current instance. It filters products with at least 10 positive reviews, where Model.PositiveReviews is a function bound to Model.Product returning a collection of reviews. ```URL http://host/service/Products?$filter=$it/Model.PositiveReviews()/$count ge 10 ``` -------------------------------- ### Example 41: Combining /$filter path segment and $filter system query option Source: https://docs.oasis-open.org/odata/odata/v4.01/os/part2-url-conventions/odata-v4.01-os-part2-url-conventions.html Combines the /$filter path segment with the $filter system query option to select red products costing less than 10. ```HTTP GET Products/$filter(@foo)?@foo=Price lt 10&$filter=Color eq 'red' ``` -------------------------------- ### Example 27: Key predicate of related entity with referential constraint Source: https://docs.oasis-open.org/odata/odata/v4.01/os/part2-url-conventions/odata-v4.01-os-part2-url-conventions.html Shows a URL using key-as-segment convention where key properties of the related entity that take part in a referential constraint are omitted. The example assumes a navigation property Items from Order to OrderItem with a referential constraint tying OrderID to the ID of Order. ```http https://host/service/Orders/1/Items/2 ``` -------------------------------- ### Example 26: Multi-part key predicate, parentheses-style and key-as-segment Source: https://docs.oasis-open.org/odata/odata/v4.01/os/part2-url-conventions/odata-v4.01-os-part2-url-conventions.html Shows two equivalent URL forms for addressing an entity with a multi-part key: the parentheses-style and the key-as-segment convention. ```http https://host/service/OrderItems(OrderID=1,ItemNo=2) https://host/service/OrderItems/1/2 ``` -------------------------------- ### Example 97: JSON batch request headers Source: https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-protocol.html Example 97: JSON batch request. Use this header structure when submitting a batch request in the JSON format. The Content-Type header must specify application/json. The OData-Version header should be included. ```http POST /service/$batch HTTP/1.1 Host: odata.org OData-Version: 4.01 Content-Type: application/json ``` -------------------------------- ### OData Parameter Alias with $expand (Example 49) Source: https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-protocol.html Example 49: uses parameter alias @m for $this to pass the manager into a filter on expanded direct reports, returning all employees, expanding their manager, and expanding direct reports with the same first name as the manager. ```HTTP GET http://host/service.svc/Employees?$expand=Manager(@m=$this;$expand=DirectReports($filter=@m/FirstName eq FirstName)) ``` -------------------------------- ### Example 100: Relative resource path Source: https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-protocol.html Resource path relative to the batch request URI format for individual requests in a batch request or change set. ```http GET People(1) HTTP/1.1 ``` -------------------------------- ### Example 46: $filter with Price lt 10.00 Source: https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-protocol.html Returns all Products whose Price is less than $10.00. The $filter system query option restricts the set of items returned. ```http GET http://host/service/Products?$filter=Price lt 10.00 ``` -------------------------------- ### Example 99: Absolute resource path with Host header Source: https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-protocol.html Absolute resource path with a separate Host header format for individual requests in a batch request or change set. ```http GET /path/service/People(1) HTTP/1.1 Host: myserver.mydomain.org:1234 ``` -------------------------------- ### Example 24: alternate key and canonical key URLs Source: https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html Shows three equivalent URLs for the same employee: one using an alternate key (SSN), one using the canonical key with property name, and one using the canonical short form. ```http http://host/service/Employees(SSN='123-45-6789') ``` ```http http://host/service/Employees(ID='A1245') ``` ```http http://host/service/Employees('A1245') ``` -------------------------------- ### Example 21: full key predicate of related entity Source: https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html Shows a URL with the full key predicate for a related entity, including all key properties. ```http https://host/service/Orders(1)/Items(OrderID=1,ItemNo=2) ``` -------------------------------- ### Skip results with $skip Source: https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-protocol.html Excludes the first five products and returns items starting at position 6. The service returns items starting at position n+1. ```HTTP GET http://host/service/Products?$skip=5 ``` -------------------------------- ### Example 96: Multipart batch request headers Source: https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-protocol.html Example 96: multipart batch request. Use this header structure when submitting a batch request in the multipart format. The Content-Type header must specify multipart/mixed with a boundary parameter as defined in RFC2046. The OData-Version header should be included. ```http POST /service/$batch HTTP/1.1 Host: odata.org OData-Version: 4.0 Content-Type: multipart/mixed; boundary=batch_36522ad7-fc75-4b56-8c71-56071383e77b ``` -------------------------------- ### Example 23: request the entity representation for an entity-id Source: https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html Shows how to resolve an entity-id using the $entity resource and the $id query option. ```http http://host/service/$entity?$id=Products(0) ``` -------------------------------- ### Valid OData URL examples Source: https://docs.oasis-open.org/odata/odata/v4.01/os/part2-url-conventions/odata-v4.01-os-part2-url-conventions.html Valid OData URLs demonstrating the representation of single quotes within string literals as two consecutive single quotes and the percent-encoding of reserved characters. The examples show both plain and percent-encoded forms. ```text http://host/service/People('O''Neil') http://host/service/People(%27O%27%27Neil%27) http://host/service/People%28%27O%27%27Neil%27%29 http://host/service/Categories('Smartphone%2FTablet') ``` -------------------------------- ### Example 77: hassubset expressions that return true Source: https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html Expressions where the first collection can be transformed into the second by reordering and/or removing items, thus returning true. ```text hassubset([4,1,3],[4,1,3]) hassubset([4,1,3],[1,3,4]) hassubset([4,1,3],[3,1]) hassubset([4,1,3],[4,3]) hassubset([4,1,3,1],[1,1]) ``` -------------------------------- ### OData URL component breakdown Source: https://docs.oasis-open.org/odata/odata/v4.01/os/part2-url-conventions/odata-v4.01-os-part2-url-conventions.html Shows the three significant parts of an OData URL: service root URL, resource path, and query options. The example uses a sample service root and a query with $top and $orderby. ```text http://host:port/path/SampleService.svc/Categories(1)/Products?$top=2&$orderby=Name \______________________________________/\____________________/ \__________________/ | | | service root URL resource path query options ``` -------------------------------- ### Example 44: Invoking bound action on filtered collection Source: https://docs.oasis-open.org/odata/odata/v4.01/os/part2-url-conventions/odata-v4.01-os-part2-url-conventions.html Invokes the Special.Cluster bound action on all products older than 3, using a /$filter path segment with a parameter alias. ```HTTP POST /service/Products/$filter(@foo)/Special.Cluster?@foo=Age gt 3 ``` -------------------------------- ### Example 19: Non-canonical URL Source: https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html Shows a non-canonical URL for an entity with a single-part key, including the key property name. ```http http://host/service/Categories(ID=1)/Products(ID=1) ``` -------------------------------- ### Example 36: Entity set restricted to VipCustomer instances Source: https://docs.oasis-open.org/odata/odata/v4.01/os/part2-url-conventions/odata-v4.01-os-part2-url-conventions.html Restricts the Customers entity set to instances of the derived type Model.VipCustomer. The result may be empty. ```http http://host/service/Customers/Model.VipCustomer ``` -------------------------------- ### Example 37: Entity restricted to a VipCustomer instance Source: https://docs.oasis-open.org/odata/odata/v4.01/os/part2-url-conventions/odata-v4.01-os-part2-url-conventions.html Two equivalent URLs that restrict a single entity to the derived type Model.VipCustomer. If the customer with key 1 is not a VipCustomer, the request results in a 404 Not Found response. ```http http://host/service/Customers/Model.VipCustomer(1) ``` ```http http://host/service/Customers(1)/Model.VipCustomer ``` -------------------------------- ### $root literal in JSON array - Example 109 Source: https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html Passes a JSON array of resource paths from $root to customers as a parameter alias, used to filter products ordered by a set of customers. ```http http://host/service/ProductsOrderedBy(Customers=@c)?@c=[$root/Customers('ALFKI'),$root/Customers('BLAUS')] ``` -------------------------------- ### Example 98: Absolute URI request URL Source: https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-protocol.html Absolute URI format for individual requests in a batch request or change set. The URL includes schema, host, port, and absolute resource path. ```http GET https://host:1234/path/service/People(1) HTTP/1.1 ``` -------------------------------- ### Example 76: substring filter for CompanyName with second and third characters 'lf' Source: https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html Returns all customers with a CompanyName that has 'lf' as the second and third characters, e.g., 'Alfreds Futterkiste'. ```http http://host/service/Customers?$filter=substring(CompanyName,1,2) eq 'lf' ``` -------------------------------- ### URL addressing references between Categories(1) and Products Source: https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html Example 28: URL addressing the references between Categories(1) and Products. This URL pattern is used to address the collection of references between a specific category and its related products. ```http http://host/service/Categories(1)/Products/$ref ``` -------------------------------- ### Example 43: Filtering categories by nested collection count Source: https://docs.oasis-open.org/odata/odata/v4.01/os/part2-url-conventions/odata-v4.01-os-part2-url-conventions.html Filters categories to those with fewer than ten products older than three, using a nested /$filter path segment inside a $filter expression. ```HTTP GET Categories?$filter=Products/$filter(Age gt 3)/$count lt 10 ``` -------------------------------- ### Example 25: Valid OData URLs for key-as-segment Source: https://docs.oasis-open.org/odata/odata/v4.01/os/part2-url-conventions/odata-v4.01-os-part2-url-conventions.html Shows valid OData URLs using the key-as-segment convention. Forward slashes in key values must be percent-encoded; single quotes are treated as part of the key value and do not need to be doubled or percent-encoded. ```http http://host/service/Employees/A1245 http://host/service/People/O'Neil http://host/service/People/O%27Neil http://host/service/Categories/Smartphone%2FTablet ``` -------------------------------- ### Example 47: $filter with Products/$count lt 10 Source: https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-protocol.html Returns all Categories with less than 10 products. Uses the $count segment within a $filter expression to limit items based on the exact count of related entities. ```http GET http://host/service/Categories?$filter=Products/$count lt 10 ``` -------------------------------- ### Example 38: Cast complex property to derived type and get property Source: https://docs.oasis-open.org/odata/odata/v4.01/os/part2-url-conventions/odata-v4.01-os-part2-url-conventions.html Casts the complex property Address to its derived type DetailedAddress, then retrieves the Location property of the derived type. ```http http://host/service/Customers(1)/Address/Model.DetailedAddress/Location ``` -------------------------------- ### Customer payload advertising bound function Source: https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-protocol.html Shows a Customer entity representation that includes the SampleEntities.MostRecentOrder function bound to the entity, with a title and target URL. This is an example response to a GET request to http://host/service/Customers('ALFKI'). ```JSON { "@context": ..., "CustomerID": "ALFKI", "CompanyName": "Alfreds Futterkiste", "#SampleEntities.MostRecentOrder": { "title": "Most Recent Order", "target": "Customers('ALFKI')/SampleEntities.MostRecentOrder()" }, ... } ``` -------------------------------- ### Primitive Literals in $filter Expressions (Example 102) Source: https://docs.oasis-open.org/odata/odata/v4.01/os/part2-url-conventions/odata-v4.01-os-part2-url-conventions.html Example 102 from section 5.1.1.14.1 shows primitive literals used in $filter expressions. It includes null, boolean, binary, integer, double, single, decimal, string, date, datetimeoffset, duration, timeofday, guid, int64, enumeration, and geography literals. In OData 4.01, duration and enumeration literals may be used with or without the type prefix, but clients targeting both 4.0 and 4.01 should always include the prefix. ```OData NullValue eq null TrueValue eq true FalseValue eq false Custom.Base64UrlDecode(binary'T0RhdGE') eq 'OData' IntegerValue lt -128 DoubleValue ge 0.31415926535897931e1 SingleValue eq INF DecimalValue eq 34.95 StringValue eq 'Say Hello,then go' DateValue eq 2012-12-03 DateTimeOffsetValue eq 2012-12-03T07:16:23Z DurationValue eq duration'P12DT23H59M59.999999999999S' DurationValue eq 'P12DT23H59M59.999999999999S' TimeOfDayValue eq 07:59:59.999 GuidValue eq 01234567-89ab-cdef-0123-456789abcdef Int64Value eq 0 ColorEnumValue eq Sales.Pattern'Yellow', ColorEnumValue eq 'Yellow', geo.distance(Location,geography'SRID=0;Point(142.1 64.1)') ``` -------------------------------- ### Select all operations in a schema with $select=DemoService.* Source: https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-protocol.html Requests all actions or functions available for each returned entity by using the star operator prefixed with the namespace or alias of the schema. ```http GET http://host/service/Products?$select=DemoService.* ``` -------------------------------- ### Use $it in $filter on Collection of Strings (Example 105) Source: https://docs.oasis-open.org/odata/odata/v4.01/os/part2-url-conventions/odata-v4.01-os-part2-url-conventions.html Example 105 from section 5.1.1.14.4 shows the $it literal used in a $filter expression on a collection of strings to refer to the current primitive instance. It filters email addresses ending with '.com'. ```URL http://host/service/Customers(1)/EmailAddresses?$filter=endswith($it,'.com') ``` -------------------------------- ### Invoke SampleEntities.CreateOrder action with If-Match Source: https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-protocol.html Invokes the SampleEntities.CreateOrder action bound to the customer identified by /Customers('ALFKI'). The request body passes the items array and discountCode parameter. The If-Match header includes the customer's ETag to ensure the action is processed only if the entity is unmodified. ```http POST http://host/service/Customers('ALFKI')/SampleEntities.CreateOrder If-Match: W/"MjAxOS0wMy0yMVQxMzowNVo=" { "items": [ { "product": 4001, "quantity": 2 }, { "product": 7062, "quantity": 1 } ], "discountCode": "BLACKFRIDAY" } ``` -------------------------------- ### Referencing an ETag with If-Match in a Batch Request Source: https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-protocol.html Batch request that first GETs an Employee (Content-ID 1) and then PATCHes the same employee with an If-Match header that references the ETag from the GET response using $1. The update is conditional on the employee not having changed. ```http POST /service/$batch HTTP/1.1 Host: host OData-Version: 4.0 Content-Type: multipart/mixed; boundary=batch_36522ad7-fc75-4b56-8c71-56071383e77b Content-Length: ### --batch_36522ad7-fc75-4b56-8c71-56071383e77b Content-Type: application/http Content-ID: 1 GET /service/Employees(0) HTTP/1.1 Host: host Accept: application/json --batch_36522ad7-fc75-4b56-8c71-56071383e77b Content-Type: application/http Content-ID: 2 PATCH /service/Employees(0) HTTP/1.1 Host: host Content-Type: application/json Content-Length: ### If-Match: $1 { "Salary": 75000 } --batch_36522ad7-fc75-4b56-8c71-56071383e77b-- ``` -------------------------------- ### Check Property Pair Against Collection of Pairs (Example 104) Source: https://docs.oasis-open.org/odata/odata/v4.01/os/part2-url-conventions/odata-v4.01-os-part2-url-conventions.html Example 104 from section 5.1.1.14.2 shows a $filter expression that checks whether a pair of properties has one of several possible pair values using the 'in' operator with a collection of collections. ```OData $filter=[FirstName,LastName] in [["John","Doe"],["Jane","Smith"]] ``` -------------------------------- ### OData Parameter Alias in $filter (Example 48) Source: https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-protocol.html Example 48: uses parameter alias @p1 in a $filter expression to return all employees whose Region property matches the string value 'WA'. The alias value is supplied as a query option in the request URL. ```HTTP GET http://host/service.svc/Employees?$filter=Region eq @p1&@p1='WA' ``` -------------------------------- ### Select all structural properties with $select=* Source: https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-protocol.html Requests all structural properties, including dynamic properties, using the star operator. The star operator SHOULD NOT introduce navigation properties, actions, or functions not otherwise requested. ```http GET http://host/service/Products?$select=* ``` -------------------------------- ### Collection Literal in URL (Example 103) Source: https://docs.oasis-open.org/odata/odata/v4.01/os/part2-url-conventions/odata-v4.01-os-part2-url-conventions.html Example 103 from section 5.1.1.14.2 shows a collection literal passed as a parameter alias in a URL. The collection is represented as a JSON array and must be percent-encoded in URLs, though some browsers may accept unencoded brackets and quotes. ```URL http://host/service/ProductsByColors(colors=@c)?@c=["red","green"] ``` -------------------------------- ### Search for term with $search=bike Source: https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-protocol.html Returns all Products that match the search term "bike". The definition of matching is implementation-dependent. ```http GET http://host/service/Products?$search=bike ``` -------------------------------- ### Use $it in Nested $filter within $expand (Example 106) Source: https://docs.oasis-open.org/odata/odata/v4.01/os/part2-url-conventions/odata-v4.01-os-part2-url-conventions.html Example 106 from section 5.1.1.14.4 shows $it used in a nested $filter expression within $expand to refer to the outer context (Customers) while the filter is evaluated in the context of Orders. It retrieves customers with orders shipped to the same city as the customer's address. ```URL http://host/service/Customers?$expand=Orders($filter=$it/Address/City eq ShipTo/City) ``` -------------------------------- ### Combine $top and $skip Source: https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-protocol.html Returns the third through seventh products. $skip is applied before $top regardless of the order in the request. ```HTTP GET http://host/service/Products?$top=5&$skip=2 ``` -------------------------------- ### Search with AND operator Source: https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-protocol.html Returns all Products that match both "mountain" and "bike". Multiple terms are separated by a space (implicit AND) or the upper-case keyword AND. ```http GET http://host/service/Products?$search=mountain AND bike ``` -------------------------------- ### Annotation value in $filter - Example 112 Source: https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html Returns products where the Price annotation @Measures.Currency equals 'EUR'. ```http http://host/service/Products?$filter=Price/@Measures.Currency eq 'EUR' ``` -------------------------------- ### Annotation value in $filter with any - Example 113 Source: https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html Returns employees that have any error messages in the Core.Messages annotation, using the any operator. ```http http://host/service/Employees?$filter=@Core.Messages/any(m:m/severity eq 'error') ``` -------------------------------- ### $this literal in $filter - Example 110 Source: https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html Selects only email addresses ending with '.com' from the EmailAddresses collection, using $this to refer to the current instance. ```http http://host/service/Customers?$select=EmailAddresses($filter=endswith($this,'.com')) ``` -------------------------------- ### Expand all navigation properties as references plus Supplier Source: https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html Expands all navigation properties of Categories as references ($ref) and also expands the Supplier navigation property fully. ```http http://host/service/Categories?$expand=*/$ref,Supplier ``` -------------------------------- ### Example 75: substring filter for CompanyName after first character Source: https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html Returns all customers with a CompanyName of 'lfreds Futterkiste' once the first character has been removed. ```http http://host/service/Customers?$filter=substring(CompanyName,1) eq 'lfreds Futterkiste' ``` -------------------------------- ### Select specific properties with $select Source: https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-protocol.html Requests only the Rating and ReleaseDate properties for the matching Products. The response includes only the specified properties along with any expanded navigation or stream properties. ```http GET http://host/service/Products?$select=Rating,ReleaseDate ``` -------------------------------- ### Path expression for complex property - Example 111 Source: https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html Accesses the Street property of the HeadquarterAddress complex property or navigation property of company 1. ```http Companies(1)/HeadquarterAddress/Street ``` -------------------------------- ### Example 80: hassubsequence expressions that return false Source: https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html Expressions where the first collection cannot be transformed into the second by removing items, thus returning false. ```text hassubsequence([4,1,3],[1,3,4]) hassubsequence([4,1,3],[3,1]) hassubsequence([1,2],[1,1,2]) ``` -------------------------------- ### Limit results with $top Source: https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-protocol.html Returns only the first five products of the Products entity set. The service returns up to n items, where n is a non-negative integer. ```HTTP GET http://host/service/Products?$top=5 ``` -------------------------------- ### Example 79: hassubsequence expressions that return true Source: https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html Expressions where the first collection can be transformed into the second by removing zero or more items, thus returning true. ```text hassubsequence([4,1,3],[4,1,3]) hassubsequence([4,1,3],[4,1]) hassubsequence([4,1,3],[4,3]) hassubsequence([4,1,3,1],[1,1]) ``` -------------------------------- ### Example 78: hassubset expression that returns false Source: https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html Expression where the first collection cannot be transformed into the second because 1 appears only once in the left operand, returning false. ```text hassubset([1,2],[1,1,2]) ``` -------------------------------- ### Built-in Filter Operations Examples Source: https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-protocol.html Examples of built-in filter operations for OData $filter expressions. The table lists comparison operators (eq, ne, gt, ge, lt, le, has, in), logical operators (and, or, not), arithmetic operators (add, sub, mul, div, divby, mod), and grouping operators (parentheses). 4.01 services MUST support case-insensitive operation names; clients targeting 4.0 services MUST use lower case names. ```odata Address/City eq 'Redmond' ``` ```odata Address/City ne 'London' ``` ```odata Price gt 20 ``` ```odata Price ge 10 ``` ```odata Price lt 20 ``` ```odata Price le 100 ``` ```odata Style has Sales.Color'Yellow' ``` ```odata Address/City in ('Redmond', 'London') ``` ```odata Price le 200 and Price gt 3.5 ``` ```odata Price le 3.5 or Price gt 200 ``` ```odata not endswith(Description,'milk') ``` ```odata Price add 5 gt 10 ``` ```odata Price sub 5 gt 10 ``` ```odata Price mul 2 gt 2000 ``` ```odata Price div 2 gt 4 ``` ```odata Price divby 2 gt 3.5 ``` ```odata Price mod 2 eq 0 ``` ```odata (Price sub 5) gt 10 ``` -------------------------------- ### Example 22: shortened key predicate of related entity Source: https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html Shows a shortened key predicate for a related entity, omitting the referential constraint key property. ```http https://host/service/Orders(1)/Items(2) ```