Hi All,
We have an environment group with multiple aliases (e.g., api-dev.com , ds.api-dev.com , dp-api-dev.com and so on ... ).
Requirement 1: Retail API Access Control:
The Retail API must only be accessible via api-dev.com .
Requests hitting the Retail API via other aliases (e.g., ds.api-dev.com ) should be rejected.
Requirement 2: Book API Access Control:
The Book API must only be accessible via dsc.api-dev.com .
Requests hitting the Book API via other aliases should be rejected.
Desired Solution: We want to implement this routing logic within the Apigee X pre-hook flow (before any proxy logic).
Current Thinking: Using a JavaScript policy in the pre-flow to inspect the Host header and conditionally route/reject requests. Followed by RaiseFault Policy to reject the request, here this possibility that individual api level, I want to apply this condition pre-hook level so that it applicable to all the apis, based on hostname it should route and others should be rejected.
In Apigee Edge, we have the concept of Virtual Hosts; however, in Apigee X, this concept does not exist. Instead, we have the organization concept. However, we do not want to create a separate organization for each host.
Are there alternative/more efficient ways to achieve this hostname-based routing in the pre-hook-flow?
Are there any built-in Apigee X policies or features that could simplify this?
Hi @Ragava12 , Yes, using a JavaScript or ServiceCallout policy in the pre-hook flow is a common way to handle this in Apigee X. Unfortunately, Apigee X does not have the old “Virtual Hosts” feature from Apigee Edge, so there’s no direct built-in setting just for hostname-based routing.
You can centralize the check in one shared flow or shared pre-hook so it applies across APIs, without repeating code everywhere.
Hi @a_aleinikov
Thank you for your replay
I'm looking for a way to apply a pre-hook condition to affect all hosted APIs. What's the best approach to identify which APIs belong to a given host? Could this be done via naming conventions, base path analysis, or some other mechanism?
Hi @Ragava12 ,
– Yes, you can use the Host header + API base path or proxy naming.
– There’s no built-in Apigee X feature to auto-map hosts to APIs.
– Best practice: set clear naming rules (like base path prefixes) and check them in the pre-hook.