# Multiple API routes within a microservice

**URL:** <https://discuss.konghq.com/t/multiple-api-routes-within-a-microservice/9664>\
**Category:** Questions\
**Tags:** kubernetes\
**Created:** [January 18, 2022, 6:42am UTC](https://discuss.konghq.com/t/multiple-api-routes-within-a-microservice/9664 "2022-01-18T06:42:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![koushik.raghu](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@koushik.raghu](https://discuss.konghq.com/u/koushik.raghu)\
**Post date:** [January 18, 2022, 6:42am UTC](https://discuss.konghq.com/t/multiple-api-routes-within-a-microservice/9664/1 "2022-01-18T06:42:58Z")

</div>

I have a sample Python flask application that renders and basic html page on “/” , inserts data into mongo on “/insertdata” and displays all data on screen for route “/displaydata” .

Sample code below -

```auto
from flask import Flask, redirect, url_for, request,render_template
app = Flask( __name__ )

@app.route('/')
def result():
   return render_template('index.html')

@app.route('/insertdata',methods=['POST','GET'])
def url_shorten():
    ''' Inserts data from UI '''
    # Insert Data From UI (index page)
    return "Susccessful"

@app.route('/displaydata',methods=['POST','GET'])
def url_widen():
    '''Display all data'''
    # Display all data insertes in collection on display button click
    return "Mongo o/p"

if __name__ == ' __main__':
   app.run(debug = True)

```

I Have deployed this sample application in a kubernetes environment (AKS) .

To configure behind kong (db-mode opensource), i have created a **service** with following url -  
[http://sampleapp.samplens.svc.cluster.local:5555/](http://sampleapp.samplens.svc.cluster.local:5555/)

And the corresponding route to be path = “/sampleapp” (Strip path and host disabled)  
On hitting the kong proxy endpoint /sampleapp , i am getting this o/p

```auto
{
  "message":"An invalid response was received from the upstream server"
}

```

Also do i need to create separate services in kong for each endpoint **insertdata** & **displaydata** and corresponding routes for the same ??

Is it possible to configure a microservice in KONG with a single route, for ex in this instance /sampleapp must perform all operations in UI without any breakage like insert and delete of data !! & without having to create individual service and routes for all endpoints within the microservice !!

---

<div class="post-metadata">

**Author:** ![traines](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.konghq.com/traines/32/158_2.png) [@traines](https://discuss.konghq.com/u/traines)\
**Post date:** [January 28, 2022, 10:20pm UTC](https://discuss.konghq.com/t/multiple-api-routes-within-a-microservice/9664/2 "2022-01-28T22:20:39Z")

</div>

You can use the same service for each endpoint as long as you don’t need to use different service-level settings (e.g. timeouts, service plugin configuration) for the different endpoints.

You probably do want to use `strip-path`, since otherwise you’ll send the `/sampleapp` prefix upstream, which the Flask app’s routing doesn’t recognize.

The invalid response indicates that something else is going wrong though (normally I’d expect you to get a 404), since it indicates that whatever the proxy received was not valid HTTP. I’d recommend checking whether your application is expecting HTTP or HTTPS on that port, and setting `konghq.com/protocol: https` in the Service annotation if so.

If that doesn’t appear to be the issue, reviewing your application logs, proxy error logs, or a [tcpdump](https://docs.konghq.com/kubernetes-ingress-controller/2.1.x/troubleshooting/#inspecting-network-traffic-with-a-tcpdump-sidecar) should clarify exactly what’s happening.
