Multiple API routes within a microservice

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 -

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/

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

{
  "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 !!

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 should clarify exactly what’s happening.