-
Notifications
You must be signed in to change notification settings - Fork 14
Suppressing OData Metadata
NOTE: This feature appears to be broken right now, and it's not us! We are investigating possible changes in the OData libraries.
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,
"[email protected]": "#Decimal",
"CreditLimit": 2000.00,
"[email protected]": "https://localhost/odata/v1/Customers(1)/REL_Orders/$ref",
"[email protected]": "https://localhost/odata/v1/Customers(1)/REL_Orders",
"[email protected]": "https://localhost/odata/v1/Customers(1)/REL_Item/$ref",
"[email protected]": "https://localhost/odata/v1/Customers(1)/REL_Item"
}
-
Tutorial 2: Building a Service from Scratch
- Creating a Basic Solution
- Enabling OData Support
- Configuring Self Hosting
- Entity Collection Endpoints
- API Documentation
- Single Entity Endpoints
- OData Query Support
- Alternate Key Endpoints
- Expanding Relations
- Postman Tests
- Supporting CRUD Operations
- Adding a Primary Key Factory
- Adding Create Endpoints
- Adding Upsert Endpoints
- Adding Patch Endpoints
- Adding Delete Endpoints
-
Harmony Core Code Generator
-
OData Aware Tools
-
Advanced Topics
- CLI Tool Customization
- Adapters
- API Versioning
- Authentication
- Authorization
- Collection Counts
- Customization File
- Custom Field Types
- Custom File Specs
- Custom Properties
- Customizing Generated Code
- Deploying to Linux
- Dynamic Call Protocol
- Environment Variables
- Field Security
- File I/O
- Improving AppSettings Processing
- Logging
- Optimistic Concurrency
- Multi-Tenancy
- Publishing in IIS
- Repeatable Unit Tests
- Stored Procedure Routing
- Suppressing OData Metadata
- Traditional Bridge
- Unit Testing
- EF Core Optimization
- Updating a Harmony Core Solution
- Updating to 3.1.90
- Creating a new Release
-
Background Information