Search code examples
apicurlrestful-architectureapi-designkong

Unique URL routing through KONG


Right now I have the following implementation working with kong. What I have working now :

What I have working now

I'm able to curl through the host where kong resides and have it forward the api request to the appropriate api host depending on what the host header contains. The results are correctly returned to me as well.

What I want to be able to do instead is curl using the api host address and have it go through kong. How would I approach this? I'm not very familiar with api frameworks or patterns and would appreciate some direction.

What I would like to happen: What I would like to happen


Solution

  • But by doing that you are going to loose the benefit of kong. According to me we are adding kong to have a controlled access to the APIs. If you call apis directly, where they are hosted, then kong will not be able to provide the benefits.

    For your problem, where you don't want to pass the host in the header you can add host to the kong when you are adding the API to kong. With that whenever request lands for api_x_command it will go to the defined host in the kong environment.

    So your URLs will be like this

    https://kongurl/api_1_command - will go to https://api_1_host/api_1_command and https://kongurl/api_2_command - will go to https://api_2_host/api_2_command

    Check the url, it will always point to Kong and command will be deciding factor, with host setting done in Kong.