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

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

主站蜘蛛池模板: 普洱| 西峡县| 含山县| 大田县| 额济纳旗| 南溪县| 修水县| 黄大仙区| 高唐县| 毕节市| 佳木斯市| 金川县| 开鲁县| 四会市| 神木县| 榆社县| 启东市| 闽清县| 云梦县| 应城市| 济阳县| 太原市| 临颍县| 涡阳县| 乾安县| 朝阳县| 科技| 黄山市| 嘉定区| 湄潭县| 天柱县| 绥中县| 绵竹市| 淄博市| 临夏市| 邻水| 湄潭县| 建德市| 赞皇县| 楚雄市| 锡林浩特市|