Skip to content

Suppressing OData Metadata

Steve Ives edited this page Aug 12, 2020 · 3 revisions

Harmony Core Logo

NOTE: This feature appears to be broken right now, and it's not us! We are investigating possible changes in the OData libraries.

Suppressing OData Metadata

OData services typically serve up some amount of metadata; information about the service and about the data entities exposed by the service. For starters, if you navigate to the base address of an OData service you will usually see a list of the entities that are being exposed.

For a default Harmony Core service running in the self-hosting process on your local development machine this information is usually available at the URL https://localhost:8086/odata/v1 and it generally looks like this:

{
  "@odata.context": "https://localhost/odata/v1/$metadata",
  "value": [
    {
      "name": "Customers",
      "kind": "EntitySet",
      "url": "Customers"
    },
    {
      "name": "Items",
      "kind": "EntitySet",
      "url": "Items"
    },
    {
      "name": "Orders",
      "kind": "EntitySet",
      "url": "Orders"
    },
    {
      "name": "OrderItems",
      "kind": "EntitySet",
      "url": "OrderItems"
    },
    {
      "name": "Vendors",
      "kind": "EntitySet",
      "url": "Vendors"
    }
  ]
}

Notice that towards the top there is a line that defines the odata.context which is a link to the full and complete OData metadata for the service. This information is in an XML format.

When you request information from a service via a GET request, you will typically also see an amount of metadata. For example, if you query for a single customer by issuing a request like this:

https://localhost:8086/odata/v1/Customers(1)

You will see a response that looks something like this:

{
  "@odata.context": "https://localhost/odata/v1/$metadata#Customers/$entity",
  "@odata.etag": "W/\"YmluYXJ5J0FDQUFBQUFBNHhsU3FRPT0n\"",
  "CustomerNumber": 1,
  "Name": "San Pablo Nursery",
  "Street": "1324 San Pablo Dam Road",
  "City": "San Pablo",
  "State": "CA",
  "ZipCode": 94806,
  "Contact": "Karen Graham",
  "Phone": "(555) 912-2341",
  "Fax": "(555) 912-2342",
  "FavoriteItem": 13,
  "PaymentTermsCode": "01",
  "TaxId": 559244251,
  "CreditLimit": 2000.00
}

In this case there are two pieces of OData metadata being returned along with the actual result. These are the odata.context that describes WHAT the result contains, and the odata.etag which is used to implement optimistic concurrency should we attempt to update the data (it's a representation of the records GRFA).

If you prefer you can suppress the output of the OData metadata by modifying the value of the HTTP Accept header that you send to the service, although you can't do that in a web browser you you'll need to use an HTTP client tool like Postman or Fiddler to allow you to do that.

By default your HTTP Accept header likely looks like this:

Accept: application/json

If you want to suppress the OData metadata you can do so like this:

Accept: application/json; odata.metadata=none

When you execute the request with this new Accept header value the metadata will not be sent and you should see output like this:

{
    "CustomerNumber": 1,
    "Name": "San Pablo Nursery",
    "Street": "1324 San Pablo Dam Road",
    "City": "San Pablo",
    "State": "CA",
    "ZipCode": 94806,
    "Contact": "Karen Graham",
    "Phone": "(555) 912-2341",
    "Fax": "(555) 912-2342",
    "FavoriteItem": 13,
    "PaymentTermsCode": "01",
    "TaxId": 559244251,
    "CreditLimit": 2000.00
}

By the way, the default level of metadata is referred to by the keyword "minimal". If you wish you can also extend the amount of metadata returned, like this:

Accept: application/json; odata.metadata=full

You will now see raw output like this:

{
    "@odata.context": "https://localhost/odata/v1/$metadata#Customers/$entity",
    "@odata.type": "#Services.Models.Customer",
    "@odata.id": "https://localhost/odata/v1/Customers(1)",
    "@odata.etag": "W/\"YmluYXJ5J0FDQUFBQUFBNHhsU3FRPT0n\"",
    "@odata.editLink": "https://localhost/odata/v1/Customers(1)",
    "CustomerNumber": 1,
    "Name": "San Pablo Nursery",
    "Street": "1324 San Pablo Dam Road",
    "City": "San Pablo",
    "State": "CA",
    "ZipCode": 94806,
    "Contact": "Karen Graham",
    "Phone": "(555) 912-2341",
    "Fax": "(555) 912-2342",
    "FavoriteItem": 13,
    "PaymentTermsCode": "01",
    "TaxId": 559244251,
    "CreditLimit@odata.type": "#Decimal",
    "CreditLimit": 2000.00,
    "REL_Orders@odata.associationLink": "https://localhost/odata/v1/Customers(1)/REL_Orders/$ref",
    "REL_Orders@odata.navigationLink": "https://localhost/odata/v1/Customers(1)/REL_Orders",
    "REL_Item@odata.associationLink": "https://localhost/odata/v1/Customers(1)/REL_Item/$ref",
    "REL_Item@odata.navigationLink": "https://localhost/odata/v1/Customers(1)/REL_Item"
}
Clone this wiki locally