-
Notifications
You must be signed in to change notification settings - Fork 23
feature request: Add path based routing #18
Comments
@mingfang so you need two different paths to go to two different APIs? That is doable now with a middleware. |
Yes, my use case is similar to the traditional Nginx reverse proxy. |
@mingfang it might not be polished experience could you tell me more about the use case? do you need to change just the host ? or are you changing the path? like removing the prefix part There are two ways to do it:
We have outstanding internal issue about the second use case. If it would work for you, I would do it today or tomorrow and send you an example how to use it. |
Ultimately I want to use APITools as an api gateway for our micro service architecture. We would use something like Consul for discovery. After more reading it looks like you guys already have the router piece. It would be perfect is this can be added to APITools as a first class citizen, |
Here is another example http://openresty.org/#DynamicRoutingBasedOnRedis |
@mingfang I made a PR to allow a change where the request will go. See #19 Would that work for you now? Without exposing the router? You could still use Lua stdlib to match strings from the start by almost regular expressions. The only way how to do path based routing in APItools is via a middleware. That middleware can use external APIs to to discovery/fetch configuration. |
I will look into using middleware. |
I'm starting to play with another API gateway named Tyk.io. |
Because we allow you to write Lua middleware, you can do the routing like: function(req, next_middleware)
if string.match(request.path, '^/some-path/') then
return http.request(req)
else
return { status = 404 }
end
end Would that be enough for you? Exposing more things in the middleware is one way road. If we do it we can't take it back easily so I would prefer exposing as little as possible. If you have something on mind, please try to express it as simple pseudo middleware similar to one I posted. That way we can iterate on what is really needed. I already have a PR #19 that allows redirecting one service to another, but it might not be needed. It really depends on your use case wether is better to use http client or some internal paths. |
Hi everyone, |
@galenzhao the functionality is not merged, but it is available in #19. |
Currently APITools supports host based routing.
For our use case, we need path based routing.
e.g. http://www.mycompany.com/api/user, we need /api/user to route to an api
The text was updated successfully, but these errors were encountered: