OData / AspNetCoreOData

ASP.NET Core OData: A server library built upon ODataLib and ASP.NET Core
Other
454 stars 159 forks source link

Need a way to build custom URIs in OData responses (i.e. "@odata.context", "@odata.nextlink") #524

Open geoffreygeslin opened 2 years ago

geoffreygeslin commented 2 years ago

I'm building an OData API that will be hosted in a multi-tenant and load-ballanced environment with multiple backend servers/nodes.

Also, web requests may be routed to backend apps by our custom web gateway. The gateway may route requests to internal and private URI with additional segments.

I'm concern of URI values returned in OData responses in production (i.e. "@odata.context", "@odata.nextlink"). Values may be incorrect for public clients and further requests... At least the host part will point to the private node/app. Also protocol and segments may conains rewrited ones by our gateway.

Is there a way to handle custom URIs in responses with AspNetCoreOData ? Maybe some "publichost" configuration setting or a dynamic handler hooked in code ?

For now, I'm thinking of implementing a custom middleware that deserialize odata responses, look for URIs in "@odata.*" elements, correct it with public values. Deserializing JSON sounds really bad for performance... maybe I can inspect OData responses before it get serialized in HTTP response ? Maybe there is a more fast and elegant solution ?

julealgon commented 2 years ago

@geoffreygeslin whenever you are going to ask a question in a Github repository, check first whether the "Discussions" feature is present, and ask through that.

Nthemba commented 2 years ago

Are you just trying to rewrite the base portion on the URI. Could you provide more information?

geoffreygeslin commented 2 years ago

@Nthemba Yes, i'm just trying to rewrite the base part of URIs in OData responses so they are consistent for public frontends. I want to know if I have to parse responses myself to replace vlues or if any parameter is already supported.

@julealgon thank you for the tip, sorry for this time...