Calling this URL from our browser (or any frontend) should give us the desired output. We’ll keep things simple and call this particular route /greetings. Now that we have restful api python flask initialized the Flask object, we can go ahead and write our first API. For now, assume you need an API that returns a simple text saying May the force be with you!
Any other HTTP call would be met by Error 405 Method not allowed. Flask achieves this with something called a Decorator in Python. Simply put, a decorator is a function that wraps another function’s execution within itself. An API route is, simply put, the URL on which the API will exist.
Your Flask app knows what to serve based on your API specification in swagger.yml. Additionally, Connexion uses swagger.yml to create API documentation for you. Before continuing on your way to building out your REST API with multiple endpoints, take a moment and explore the API a bit more in the next section. When you use OpenAPI with Swagger, you can create a user interface (UI) to explore the API.
When you define an API, you must include the version of your OpenAPI definition. The version string is important because some parts of the OpenAPI structure may change over time. In the next sections, you’ll expand the project and add your first REST API endpoints.
When you interact with a database in your Python code, you may think twice about whether you want to write pure SQL commands. As you learned above, writing SQL may not only feel inconvenient, but it can cause security issues. If you don’t want to worry too much about database interaction, a package like SQLAlchemy can help you out.
NOSSOS CLIENTES