What is Flask-RESTful?
Flask-RESTful is a Flask extension that allows us to quickly develop RESTful APIs. Compared to the built-in wrapper, @app.route('/'), which we discussed in the previous chapter, Flask-RESTful allows us to maintain and structure the API endpoints in a much better and easier way.
In this chapter, we will develop our project using this Flask extension so that you will see how we can structure our endpoints.
Using Flask-RESTful to Develop Our Recipe-Sharing Platform, "Smilecook"
In this book, we are going to develop a recipe-sharing platform called Smilecook. Beginning with this chapter, we will start adding functions to it. We believe this approach will help you learn about the key concepts and skills you will need so that you can develop this application and help it reach its full potential, while at the same time helping you understand the entire development workflow.
First, we will build the basic CRUD functions of the recipes. The Flask-RESTful package allows us to structure our code in a more comprehensive way. We will define certain methods in a resource and link them to the endpoints. The flow of a GET request, for example, will be for the request to be sent to the endpoints (http://localhost:5000/recipes), which will then be handled by the GET method we are going to implement in the resource. This will result in the recipes being returned to us.
Apart from the basic CRUD functions, we will also implement the publish and unpublish functions on these recipes. This can be done through the PUT and DELETE methods, which can be found in the RecipePublishResource class. We will link these two methods to the http://localhost:5000/recipes/1/publish endpoint (for the recipe whose ID = 1). For details of our endpoint design, please refer to the following table:
Figure 2.1: Details of our endpoint designs