4

I am trying to use swagger ui as a frontend to query my flask application. I'm using Flasgger I tried a toy example as shown below

from flasgger import Swagger
from flask import Flask, logging

app = Flask(__name__)
Swagger(app)


# ENDPOINT = 1
@app.route('/hello',methods=['GET'])
def helloapp():
    return 'Hello World'

if __name__ == '__main__':
    app.run(debug=True,threaded=True,port=7005)
    file_handler = logging.FileHandler('app.log')
    app.logger.addHandler(file_handler)
    app.logger.setLevel(logging.INFO)

When i try to query the endpoint http://localhost:7005/hello. I get the result with 'Hello World'.

If I try to query http://localhost:7005/apidocs/ This shows me the base UI enter image description here


But, when I try to query the endpoint root. The swagger UI does not show up. It throws me a 404 Error

Not Found
The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.

Any pointers as to what is the issue ?.

Betafish
  • 1,212
  • 3
  • 20
  • 45

1 Answers1

1

Try to add the endpoint root to your routes like this:

@app.route('/')

@app.route('/hello',methods=['GET'])
# ... 

Because you didn't define it as a route, it cannot be found on the server. I hope that this will help you

Avery
  • 2,270
  • 4
  • 33
  • 35
Hasni Iheb
  • 282
  • 2
  • 12