ObjectStackObjectStack

Odata

Odata protocol schemas

OData v4 Protocol Support

Open Data Protocol (OData) v4 is an industry-standard protocol for building

and consuming RESTful APIs. It provides a uniform way to expose, structure,

query, and manipulate data.

Overview

OData v4 provides standardized URL conventions for querying data including:

  • $select: Choose which fields to return

  • $filter: Filter results with complex expressions

  • $orderby: Sort results

  • $top/$skip: Pagination

  • $expand: Include related entities

  • $count: Get total count

Use Cases

  1. Enterprise Integration
  • Integrate with Microsoft Dynamics 365

  • Connect to SharePoint Online

  • SAP OData services

  1. API Standardization
  • Provide consistent query interface

  • Standard pagination and filtering

  • Industry-recognized protocol

  1. External Data Sources
  • Connect to OData-compliant systems

  • Federated queries

  • Data virtualization

@see https://www.odata.org/documentation/

@see https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html

@example OData Query


GET /api/odata/customers?

$select=name,email&

$filter=country eq 'US' and revenue gt 100000&

$orderby=revenue desc&

$top=10&

$skip=20&

$expand=orders&

$count=true

@example Programmatic Use


const query: ODataQuery = \{

select: ['name', 'email'],

filter: "country eq 'US' and revenue gt 100000",

orderby: 'revenue desc',

top: 10,

skip: 20,

expand: ['orders'],

count: true

\}

Source: packages/spec/src/api/odata.zod.ts

TypeScript Usage

import { ODataConfig, ODataError, ODataFilterFunction, ODataFilterOperator, ODataMetadata, ODataQuery, ODataResponse } from '@objectstack/spec/api';
import type { ODataConfig, ODataError, ODataFilterFunction, ODataFilterOperator, ODataMetadata, ODataQuery, ODataResponse } from '@objectstack/spec/api';

// Validate data
const result = ODataConfig.parse(data);

ODataConfig

Properties

PropertyTypeRequiredDescription
enabledbooleanEnable OData API
pathstringOData endpoint path
metadataObjectoptionalOData metadata configuration

ODataError

Properties

PropertyTypeRequiredDescription
errorObject

ODataFilterFunction

Allowed Values

  • contains
  • startswith
  • endswith
  • length
  • indexof
  • substring
  • tolower
  • toupper
  • trim
  • concat
  • year
  • month
  • day
  • hour
  • minute
  • second
  • date
  • time
  • now
  • maxdatetime
  • mindatetime
  • round
  • floor
  • ceiling
  • cast
  • isof
  • any
  • all

ODataFilterOperator

Allowed Values

  • eq
  • ne
  • lt
  • le
  • gt
  • ge
  • and
  • or
  • not
  • (
  • )
  • in
  • has

ODataMetadata

Properties

PropertyTypeRequiredDescription
namespacestringService namespace
entityTypesObject[]Entity types
entitySetsObject[]Entity sets

ODataQuery

Properties

PropertyTypeRequiredDescription
$selectstring | string[]optionalFields to select
$filterstringoptionalFilter expression (OData filter syntax)
$orderbystring | string[]optionalSort order
$topintegeroptionalMax results to return
$skipintegeroptionalResults to skip
$expandstring | string[]optionalNavigation properties to expand (lookup/master_detail fields)
$countbooleanoptionalInclude total count
$searchstringoptionalSearch expression
$formatEnum<'json' | 'xml' | 'atom'>optionalResponse format
$applystringoptionalAggregation expression

ODataResponse

Properties

PropertyTypeRequiredDescription
@odata.contextstringoptionalMetadata context URL
@odata.countintegeroptionalTotal results count
@odata.nextLinkstringoptionalNext page URL
valueRecord<string, any>[]Results array

On this page