In Flask-RESTful, API resources are modeled as Python classes that extend the Resource class, and on line (10) in the following snippet, we see the LEDControl(Resource) class defined that will contain the logic used to control our LED. Later on, we will see how we register this class with Flask-RESTful so that it responds to client requests:
class LEDControl(Resource): # (10)
def __init__(self):
self.args_parser = reqparse.RequestParser() # (11)
self.args_parser.add_argument(
name='level', # Name of arguement
required=True, # Mandatory arguement
type=inputs.int_range(0, 100), # Allowed 0..100 # (12)
help='Set LED brightness level {error_msg}',
default=None)
On line (11), we create an instance of RequestParser() and assign it to the args_parser variable...