Skip to Content

Four years after OData V4 became an OASIS standard, and two years after it became the ISO/IEC 20802 standard, the first “feature pack” for OData V4 has been officially published.

The complete set of changes is described in What’s New in OData Version 4.01.

For me the most important new features are:

  • JSON Metadata
  • JSON Batch Format
  • Deep Update and Deep Upsert
  • Mass Operations
  • Improved Query Capabilities

JSON Metadata

Finally there’s a JSON format for $metadata, so clients don’t need an XML parser any more for interacting with an OData service. This format is very streamlined, so

<EntityType Name="Country">
  <Key>
  <PropertyRef Name="Code"/>
  </Key>
  <Property Name="Code" Type="Edm.String" MaxLength="2" Nullable="false"/>
  <Property Name="Name" Type="Edm.String"/>
</EntityType>

simply becomes

"Country": {
  "$Kind": "EntityType",
  "$Key": [
    "Code"
  ],
  "Code": {
    "$MaxLength": 2
  },
  "Name": {
    "$Nullable": true
  }
}

And of course on the wire all whitespace is removed:

"Country":{"$Kind":"EntityType","$Key":["Code"],"Code":{"$MaxLength":2},"Name":{"$Nullable":true}}

JSON Batch Format

The multi-part format for $batch was tricky to create and hard to read; now there is a JSON format for batch requests and responses which is simply an array of request or response objects:

{
  "requests": [
    {
      "id": "0",
      "method": "get",
      "url": "/service/Customers('ALFKI')"
    },
    {
      "id": "1",
      "atomicityGroup": "group1",
      "dependsOn": ["0" ],
      "method": "patch",
      "url": "/service/Customers('ALFKI')",
      "headers": {
        "Prefer": "return=minimal"
      },
      "body": <JSON representation of changes to Customer ALFKI>
    },
    {
      "id": "2",
      "atomicityGroup": "group1",
      "method": "post",
      "url": "/service/Customers",
      "body": <JSON representation of a new Customer entity>
    },
    {
      "id": "3",
      "dependsOn": [ "group1" ],
      "method": "get",
      "url": "/service/Products"
    }
  ]
}

While we were at it, we optimized it for parallelized execution and better dependency control between individual requests within the batch via atomicityGroup and dependsOn.

Deep Update and Deep Upsert

You already could create a deeply nested tree of entities in one go with Deep Insert, now you can PATCH an entity graph by sending a nested tree of stuff to add or change, and if the PATCH target doesn’t exist yet, it is simply created, thus Deep Upsert.

Mass Operations

Even though the new JSON Batch Format is easier to create, some things are more naturally expressed as a mass operation.

Simply PATCH an entity set with an array of many new/changed entities, and of course this can be an array of Deep Upsert structures.

UPDATE WHERE and DELETE WHERE now have their OData counterparts:

PATCH /service/Products/$filter=@bar/$each?@bar=Color eq 'beige-brown'
Content-Type: application/json
 
{
  "Color": "taupe"
}

or

DELETE /service/Products/$filter=@foo/$each?@foo=Age gt 3

Improved Query Capabilities

Ever wanted to compute a virtual property on the fly?

GET Sales?$compute=Revenue sub Costs as Profit,Profit divby Revenue as Margin

Or check whether a property’s value is in a list of values?

GET People?$filter=FirstName in ('Fred','George','Harry')

When will these features be available in an OData service near you? Well, that’s an interesting question 🙂

Ralf

To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

Leave a Reply