I have a service named alpha (created using python-django) that runs on http://127.0.0.1:9000
and has these two endpoings
/health
returns{"health": "OK"} status 200
/codes/<str:code>
returns{"code": code} status 200
I also have a kong api-gateway in the db-less declarative mode that runs on localhost port 80
in kong.yaml I have two services
services:
- name: local-alpha-health
url: http://host.docker.internal:9000/health
routes:
- name: local-alpha-health
methods:
- GET
paths:
- /alpha/health
strip_path: true
- name: local-alpha-code
url: http://host.docker.internal:9000/code/ # HOW TO WRITE THIS PART???
routes:
- name: local-alpha-code
methods:
- GET
paths:
- /alpha/code/(?<appcode>\d+) # Is this right???
strip_path: true
- If I send a
GET
request tohttp://127.0.0.1/alpha/health
it returns{"health": "OK"} status 200
which shows kong is working. - I want to send a request such as
http://127.0.0.1/alpha/code/123
and I expect to receive{"code": 123} status 200
but I don't know how to setup kong.yaml file to do this. If I send a request tohttp://127.0.0.1/alpha/code/123
I get 404 from (from the alpha django application) which means kong is routing the request to alpha service but if I send a request tohttp://127.0.0.1/alpha/code/abc
I get{"message": "no Route matched with those values"}
which shows the regex is working
I could do this
services:
- name: local-alpha-health
url: http://host.docker.internal:9000/
routes:
- name: local-alpha-health
methods:
- GET
paths:
- /alpha
strip_path: true
Then a request sent to http://127.0.0.1/alpha/code/123
would go to ``http://127.0.0.1:9000/code/123` but I cannot control with regex
Any idea How to route requests to a dynamic endpoint on kong api-gateway?
This content seems related but cannot figure it out how to set it up https://docs.konghq.com/gateway-oss/2.5.x/proxy/