July 2019
Beginner to intermediate
302 pages
9h 38m
English
The following lines of code are the complete RESTful API for the Product model. These code snippets will go into the views.py file.
Start with imports and add parser:
import jsonfrom flask import abortfrom flask_restful import reqparse
parser = reqparse.RequestParser()
parser.add_argument('name', type=str)
parser.add_argument('price', type=float)
parser.add_argument('category', type=dict)
In the preceding snippet, we created parser for the arguments that we expected to have in our requests for POST and PUT. The request expects each of the arguments to have a value. If a value is missing for any argument, then None is used as the value.
Write the method as shown in the following code block to fetch products:
class ProductApi(Resource): ...