Search code examples
c#asp.net-web-apiodata

OData hypermedia


A long time ago when I first looked at OData response payloads to GET requests contained links to other entities or entity sets (e.g. an OrderHeader entity would contain a link to the order's OrderDetails). I believe the correct term for this is hypermedia.

Today I'm checking out OData again and have built a OData v4 service using ASP.Net Web API however no such hypermedia links are being returned in the payloads. Why is this? Is it because the payload is now JSON (whereas when I looked years ago it was XML)? Is there any way to include hypermedia links in the payload?

Here's what I've built. I have an entity called Proposition:

public class Proposition
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string Description { get; set; }
    public ICollection<Event> Events { get; set; }
}

Notice that a Proposition has a collection of Events. I was hoping that when I requested a Proposition via the OData endpoint that I would get a link to the Events resource, but I don't: enter image description here

I've found some information at OData JSON Format Version 4.0 Plus Errata 02#JSON Format Design that suggests adding $format=odata.metadata=full to the URL will return what I need:

The odata.metadata=full format parameter indicates that the service MUST include all control information explicitly in the payload

(odata.metadata=full)

but I've tried that and I'm not getting back any such metadata (screenshot this time from Postman): enter image description here Postman shows me that what got returned was odata.metadata.minimal:

enter image description here

Why is it ignoring my request for full metadata?


Solution

  • You should be able to add $format=application/json;odata.metadata=full to your querystring to achieve this via a GET request.