LoveMeow
LoveMeow

Reputation: 4028

Flask and Swagger UI does not work?

I am trying to create a RESTful app using Flask and swagger. But when I run the endpoint I do not see the methods documented in the browser like described here for example http://michal.karzynski.pl/blog/2016/06/19/building-beautiful-restful-apis-using-flask-swagger-ui-flask-restplus/ Instead just the 404 not found error. Here is my code:

def init_deserializer_restful_api():
    # Get port number for the web app.
    PORT = 8000

    # Initiate the Flask app
    app = Flask(__name__)
    Swagger(app)
    CORS(app)

    # Handler for deserializer
    @app.route("/deserialize", methods=['POST','GET'])
    def handle_deserialization_request():
    # Method description
    # Method content

App is run like this:

app.run(port=PORT, host="0.0.0.0")

I run http://localhost:8000/deserializer I get The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.

Questions: 1. How do I feed flask the request.json it requires? 2. How do I get swagger to work?

Upvotes: 0

Views: 6653

Answers (1)

Vivek Kalyanarangan
Vivek Kalyanarangan

Reputation: 9081

try localhost:8000/apidocs/index.html

Explanation This is the default endpoint of Swagger. What you were trying to do is accessing one endpoint of your API and expecting it to render the Swagger UI. Swagger UI is an ADDITIONAL endpoint to your API which lists and lets you try all other endpoints. Hope that helps!

Upvotes: 1

Related Questions