官术网_书友最值得收藏!

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

主站蜘蛛池模板: 邵阳市| 尼木县| 丰顺县| 哈密市| 星座| 德保县| 宜兴市| 靖西县| 观塘区| 鹤山市| 绥阳县| 达拉特旗| 汝州市| 尉氏县| 会泽县| 曲阳县| 涞源县| 沐川县| 绥中县| 阳谷县| 济源市| 泰宁县| 镇平县| 衡阳市| 泰兴市| 景谷| 祁连县| 镇坪县| 于田县| 铜鼓县| 慈利县| 潮安县| 古蔺县| 嵊泗县| 萨嘎县| 广安市| 泰和县| 新营市| 清新县| 平陆县| 隆安县|