Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

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 3,227
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