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
  2. API Standardization

    • Provide consistent query interface
    • Standard pagination and filtering
    • Industry-recognized protocol
  3. External Data Sources

    • Connect to OData-compliant systems
    • Federated queries
    • Data virtualization

See also: https://www.odata.org/documentation/

See also: 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 { ODataConfigSchema, ODataErrorSchema, ODataFilterFunctionSchema, ODataMetadataSchema, ODataQuerySchema, ODataResponseSchema } from '@objectstack/spec/api';
import type { ODataConfig, ODataError, ODataFilterFunction, ODataMetadata, ODataQuery, ODataResponse } from '@objectstack/spec/api';

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

ODataConfig

Properties

PropertyTypeRequiredDescription
enabledbooleanEnable OData API
pathstringOData endpoint path
metadata{ namespace: string; entityTypes: object[]; entitySets: object[] }optionalOData metadata configuration

ODataError

Properties

PropertyTypeRequiredDescription
error{ code: string; message: string; target?: string; details?: object[]; … }

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

ODataMetadata

Properties

PropertyTypeRequiredDescription
namespacestringService namespace
entityTypes{ name: string; key: string[]; properties: object[]; navigationProperties?: object[] }[]Entity types
entitySets{ name: string; entityType: string }[]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 (reference fields: lookup/master_detail/user/tree)
$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