Open Data Protocol (OData) 是基於 HTTP/AtomPub/JSON 的資料存取協定,讓用戶端能像查詢 SQL 一樣透過 URL 對資源進行篩選、排序、分頁、展開關聯,適用於跨平台資料整合。
https://services.odata.org/Northwind/Northwind.svc/https://services.odata.org/OData/OData.svc/GET /Northwind.svc/Products
GET /Northwind.svc/Categories
預設回傳 Atom/XML 格式。
/Products?$format=json
/Categories?$format=json

/Products?$select=ProductID,ProductName&$format=json

先查 /$metadata 確認關聯:Product 擁有 Category、Supplier、Order_Details。

/Products?$format=json&$expand=Supplier
/Products?$format=json&$expand=Supplier,Category

/Products?$format=json&$skip=10&$top=10
/Products?$format=json&$filter=UnitPrice gt 20
/Products?$format=json&$filter=ProductName eq 'Chai'
運算子:eq, ne, gt, ge, lt, le, and, or, not;函式:substringof, startswith, endswith, year, month, day。
/Products?$format=json&$orderby=UnitPrice desc
/Products?$format=json&$orderby=Category/CategoryName,ProductName
/Products/$count
/Products?$inlinecount=allpages&$top=5
/Northwind.svc:服務文件,列出所有 EntitySet。/Northwind.svc/$metadata:EDMX 中繼資料,定義實體型別、屬性、關聯、服務操作。掌握查詢語法後,下一篇將示範如何在 .NET 中使用 WCF Data Service 快速建立自己的 OData 端點。