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

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

主站蜘蛛池模板: 巴彦淖尔市| 翁源县| 抚顺市| 酒泉市| 鹤峰县| 阳新县| 栖霞市| 清流县| 阜宁县| 班戈县| 明水县| 嘉义市| 珲春市| 乡宁县| 红安县| 大安市| 韶山市| 昂仁县| 涞源县| 阳信县| 和政县| 肥西县| 平原县| 武功县| 临西县| 通城县| 湘阴县| 揭西县| 石屏县| 峡江县| 思南县| 永胜县| 桂东县| 呈贡县| 玛纳斯县| 房山区| 沙田区| 岑巩县| 广汉市| 滨州市| 陵川县|