We just want to be able to create users and use them to authenticate requests. Thus, we will just focus on creating resource classes with just a few methods. We won't create a complete user management system.
We will create the resource classes that represent the user and the collection of users. First, we will create a UserResource
class, which we will use to represent a user resource. Open the views.py
file within the service
folder and add the following lines after the line that creates the Api
instance named service
and before the declaration of the NotificationResource
class. The code file for the sample is included in the restful_python_2_03_02
folder, in the Flask01/service/views.py
file:
class UserResource(AuthenticationRequiredResource): def get(self, id): user = User.query.get_or_404(id) result = user_schema.dump(user).data return result
The UserResource
class is a subclass of the previously coded AuthenticationRequiredResource...