Kong : parameter support in url

I’m trying to create api which has parameters in its url.

API:
http://example.com/lead/{latitude}/{longitude}
http://example.com/lead/{tile}/road

Is it supported in kong? If yes then please point to any documentation. If no then is there any other workaround.

Note: Also I’m just getting started with kong. Please point me to any tutorials, blogs, courses, etc.

Hi, and welcome!

The best resource on this topic if you are just getting started is the Proxy Guide:

https://docs.konghq.com/1.1.x/proxy/

Long story short, Kong doesn’t have to know about the dynamic segments in your URL path component. Specifying a prefix (e.g. /lead) will work just fine. Most likely, your API will return HTTP 404 in the event than a request hits a non-existing path (e.g. /lead/foo).

If you’d rather enforce that Kong can only proxy those two paths, then a regex path is your goto choice (also documented in the above resource). You can leverage regex capture groups to extract the value of those path segments. Have a look at this post for an in-depth dive into regex paths and capture groups:

1 Like

Good afternoon,

i am also trying to do what [milind1] is trying to do. Specifially I: am trying to define this in a declarative config file. But my problem is I am not sure what syntax would need to be setup in order for my parameters to be added to do upstream server request.

Here is what I current have in my kong file

format_version: "1.1"

services:
- name: find_test_id
  url: http://address:8080/rest/app/  \\i am assuming that the plugin will add the test id to this url
  routes:
  - name: find_test_id
    paths:
    - /find_test_id/id:(?<id>\d+)  \\is this correct?
  plugins:
  - name: request-transformer
    route: find_test_id
	content-type:application/json
    config:
        add:
          body:["id"]

When I try to send a request to https://localhost:8443/find_test_id/id:20 , the upstream rqt does not add the id value to the end of the url and therefore returns a 500 error.
{“message”:“An unexpected error occurred”}

Any input on this issue will greatly be appreciated.

Hello! i have the same issue, how do u get the path params!?