I have a simple Odata V4 service that returns persons.
This service is not accessible directly:
- it is accessible through Apigee, ie with http://myApigeeServer/Person
- then Apigee is pointing on a load balancer, ie with http://myLoadBalancer/Person
- finally there is actually two servers behind my load balancer virtual IP, ie with http://myFirstServer/Person and http://mySecondServer/Person
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...