0

I have a simple Odata V4 service that returns persons.

This service is not accessible directly:

My problem is that we can see the real final server URL in the service response "@odata.context" metadata, so a call to http://myApigeeServer/Person('foo') can lead to two responses:

{
    "@odata.context": "http://myFirstServer/$metadata#Person/$entity",
    "FirstName": "John",
    "LastName": "Doe",
    "Phone@odata.type": "#Collection(String)",
    "Phone": [
        "+123456789"
    ],
}

Or

{
    "@odata.context": "http://mySecondServer/$metadata#Person/$entity",
    "FirstName": "John",
    "LastName": "Doe",
    "Phone@odata.type": "#Collection(String)",
    "Phone": [
        "+123456789"
    ],
}

I really must hide the final servers names. So my question is: is it possible to totally remove the "@odata.context" metadata or to customize it ? In my case customization would mean forcing the "@odata.context" metadata value with the Apigee URL.

[---EDIT----]

Based on the link proposed by Dylan Nicholson (thanks!), indeed it exists a hook on the ODataMediaTypeFormatter that enables to change the service URI base address.

But in my tests, it didn't work/I didn't manage to make it work for the @odata.context URI. So from links to links and tests to tests, I arrived here and lencharest's solution works perfectly well: using a custom URL helper that rewrites each link base address. I'll see in the future if it's too brutal...

Max Xapi
  • 750
  • 8
  • 22

1 Answers1

1

@Max

To suppress the @odata.context, you can use "application/json;odata.metadata=none"

Sam Xu
  • 3,264
  • 1
  • 12
  • 17
  • It's a good workaround to know, thanks Sam. It works and I've used it temporarily. But it's a little bit radical for me, I rather prefer modify the link than hiding all the metadata. See what I've done in my edit – Max Xapi Dec 13 '17 at 10:06