October 2018
Intermediate to advanced
332 pages
8h 9m
English
As listed in the table at the beginning of this chapter, PUT requests are used to change the values of an existing resource. Like the post method, the first thing that we should do is create a new parser in parsers.py, as follows:
post_put_parser = reqparse.RequestParser()post_put_parser.add_argument( 'title', type=str, location=('json', 'values'))post_put_parser.add_argument( 'text', type=str, location=('json', 'values'))post_put_parser.add_argument( 'tags', type=str, action='append', location=('json', 'values'))
The logic for the put method is very similar to the post method. The main difference is that each change is optional and any request that does not provide post_id is denied, as shown in the following code:
...def