How to check if an API's "uris" property contains current request uri?

271 views
Skip to first unread message

jg

unread,
Nov 10, 2017, 10:06:44 AM11/10/17
to Kong
Hello Kongers,
I'm new to Kong and Lua, but it's been great so far. I'm having an issue when developing a plugin that I was hoping to get some help with. How do you tell if the current request matches a uri in an API's "uris" array?

If the API has uris of "/test","/what" how can I tell if a consumer calls the API gateway route of "example.com/what" from a plugin (from within the plugin's access method)?

Any help would be appreciated.

mvanho...@xebia.com

unread,
Nov 10, 2017, 12:49:56 PM11/10/17
to Kong
You could retrieve the current uri though ngx.var.uri but I would say it is against the design of kong.  If you want different behaviour for /what as for /test than you declare two different plugins..

Cheers,

Mark

Thibault Charbonnier

unread,
Nov 10, 2017, 1:24:55 PM11/10/17
to kong...@googlegroups.com
Hi,

If you are using Kong 0.11 or above, you can use the following structure
in the access() handler and all subsequent ones:

ngx.ctx.router_matches

It contains the following properties:

uri (string or nil)
host (string or nil)
method (string or nil)
uri_captures (table or nil)

This is not yet officially documented as it isn't quite yet part of our
official API.

Best,
Thibault
> --
> You received this message because you are subscribed to the Google
> Groups "Kong" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to konglayer+...@googlegroups.com
> <mailto:konglayer+...@googlegroups.com>.
> To post to this group, send email to kong...@googlegroups.com
> <mailto:kong...@googlegroups.com>.
> Visit this group at https://groups.google.com/group/konglayer.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/konglayer/833c4a5b-1963-45f2-9ab9-7caac815ced3%40googlegroups.com
> <https://groups.google.com/d/msgid/konglayer/833c4a5b-1963-45f2-9ab9-7caac815ced3%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

jg

unread,
Nov 10, 2017, 5:31:45 PM11/10/17
to Kong
Thank you!
Reply all
Reply to author
Forward
0 new messages