I am trying to mimic the behavior of NuGet.org that returns a package Id for an example URL like:
http://www.nuget.org/api/v2/Packages(Id='Nuget.Core',Version='2.8.3')/Id
This response looks like:
<d:Id xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
Nuget.Core
</d:Id>
I can create a similar WebApi OData route using PropertyRoutingConvention and creating a method on my controller:
public IHttpActionResult GetId([FromODataUri] string id, [FromODataUri] string version)
{
var package = Repository.FindPackage(id, new SemanticVersion(version));
return Ok(package.Id);
}
This action is invoked but the response always has Content-Type of application/json:
curl -i -q -H 'Accept: application/atom+xml' http://localhost:9001/api/odata/Packages(Id='Nuget.Core',Version='2.8.3')/Id
HTTP/1.1 200 OK
Content-Type: application/json; odata=minimalmetadata; streaming=true; charset=utf-8
DataServiceVersion: 3.0
{
"odata.metadata":"http://localhost:9001/api/odata/$metadata#Edm.String","value":"Nuget.Core"
}
In addition to content-negotiation not working, how can I include the property name in the response to make it behave like how NuGet.org behaves?
For sake of clarity, complete code is available at https://github.com/themotleyfool/NuGet.Lucene