Python API Development Fundamentals by Jack Chan Ray Chung and Jack Huang

Python API Development Fundamentals by Jack Chan Ray Chung and Jack Huang

Author:Jack Chan, Ray Chung, and Jack Huang
Language: eng
Format: mobi
Publisher: Packt Publishing Pvt Ltd
Published: 2019-11-20T16:00:00+00:00


Using the webargs Package to Parse the Request Arguments

The request arguments, also known as the query string, are the arguments that we can pass in through the URL. For example, in the URL http://localhost/testing?abc=123, abc=123 is the request argument.

webargs is a package for parsing request arguments. We will create a new endpoint, GET http://localhost:5000/user/{username}/recipes, to get all the published recipes from a particular author. For this endpoint, we will pass in the visibility request argument. The visibility request argument can have a value of public, private, or all. The default value is public. If it is private or all, the user needs to be authenticated first.

If you want to get only the unpublished recipes, you can add the request argument visibility=private. So, the URL will look like this: http://localhost:5000/user/{username}/recipes?visibility=private. The webargs package provides functions to parse this visibility=private argument in the URL, and then our Smilecook application will know this request is asking for private information in the recipe. Our Smilecook application will then determine whether the authenticated user is the author. If they are, it will return all the unpublished recipes. Otherwise, there is no permission for the user to see the unpublished recipes.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.