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

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

主站蜘蛛池模板: 文安县| 平远县| 清河县| 呼玛县| 南涧| 施甸县| 仁化县| 黄冈市| 上杭县| 朝阳区| 茌平县| 和田市| 济源市| 绵竹市| 简阳市| 姜堰市| 两当县| 霍山县| 德保县| 泽普县| 平湖市| 平江县| 张家界市| 安岳县| 丰原市| 肥东县| 左权县| 巴中市| 莲花县| 邹平县| 江孜县| 赫章县| 军事| 常州市| 奈曼旗| 安义县| 江城| 确山县| 思茅市| 肇庆市| 墨脱县|