Best Practice for API Proxy that exposes multiple resource paths and proxies to multiple endpoints

Not applicable

I have a proxy with a path of /foo and I want my API to have.

/foo/weather <-- will go to weather API

/foo/location <-- will go to geocode API

/foo/businesses <-- will go to Yelp API

From what I can tell, I can do this in a couple of ways..

  1. I can have conditional flows (based on verb+path) in my proxy endpoint.
  2. I can have multiple target endpoints and establish route rules in my proxy endpoint.

Can somebody with a good handle on best practices comment on pros and cons of the two approaches (plus others if I'm missing any -- I'm aware I can probably do the whole thing in Javascript/node or Java but those don't sound like a good idea.

I am looking for specific architectural reasons, and maybe the implementation options for each.. For example, with option #1, I think I can either do a service callout, OR I can alter the request.targetUrl property (not sure about name)... So if option #1 has two derivatives, is one better than the other, etc?

Thanks in advance for the help

Solved Solved
0 3 2,733
1 ACCEPTED SOLUTION

Hi @Kd Ford,

From the best practices point of view, you should always try to adhere to separation of concerns. If they serve the same purpose then keep them in one proxy and use route rules to route request pertaining to a target system based on proxy.pathsuffix and other conditions based on your requirement.

As you mentioned /foo/weather is dealing with only with weather APIs then keep it in a separate proxy with basepath /foo/weather similarly for others.

As you mentioned using conditional flows for a target system by overwriting "target.url", this will not be a good approach and will give you maintenance nightmare.

View solution in original post

3 REPLIES 3

Hi @Kd Ford,

From the best practices point of view, you should always try to adhere to separation of concerns. If they serve the same purpose then keep them in one proxy and use route rules to route request pertaining to a target system based on proxy.pathsuffix and other conditions based on your requirement.

As you mentioned /foo/weather is dealing with only with weather APIs then keep it in a separate proxy with basepath /foo/weather similarly for others.

As you mentioned using conditional flows for a target system by overwriting "target.url", this will not be a good approach and will give you maintenance nightmare.

Thank you Mohammed for the answer/clarification.

Top dig a little deeper... I would configure route rules in my proxy endpoint and then add an additional target endpoint for every new path I need to serve (while considering associating like-routes within a single api proxy and different routes in other api proxies? such as the pseudo code below?

assuming I want this in one api proxy

  • /theaters
  • /theaters/{id}
  • /theaters/{id}movies
  • /theaters/{id}/movies/{id}
  • proxy endpoints
    • default
      • route rules
        • <RouteRule name="listTheaters">
          • <Condition>(proxy.pathsuffix MatchesPath "/theaters") and (request.verb = "GET")</Condition> <TargetEndpoint>listTheaters</TargetEndpoint>
        • <RouteRule name="findTheaterById">
          • <Condition>(proxy.pathsuffix MatchesPath "/theaters/*") and (request.verb = "GET")</Condition>
          • <TargetEndpoint>findTheaterById</TargetEndpoint>
        • <RouteRule name="listMovies">
          • <Condition>(proxy.pathsuffix MatchesPath "/theaters/*/movies") and (request.verb = "GET")</Condition>
          • <TargetEndpoint>listMovies</TargetEndpoint>
        • <RouteRule name="findMovieById">
          • <Condition>(proxy.pathsuffix MatchesPath "/theaters/*/movies/*") and (request.verb = "GET")</Condition>
          • <TargetEndpoint>findMovieById</TargetEndpoint>
        • <RouteRule name="default">
          • <TargetEndpoint>default</TargetEndpoint>
            • ### This should probably be my listTheaters endpoint, but I've configured my proxy url at one level higher, like... /myapp... If I configure the proxy url as /myapp/theaters, then I would use this default RouteRule (and the default target endpoint) to service GET requests to "listTheaters", right?
  • target endpoints
    • listTheaters
      • http target url...
      • etc....
  • etc...

Do I have it?

Hi @Kd Ford ,

Do you have different target systems from where you are fetching data for /theaters , /theaters/{id}/movies?

If they are all going to one target system then use conditional flows in this scenario.