The get() class method handles HTTP GET requests for our LEDControl resource. It's what handled our URL request when we tested the API previously with the following command:
$ curl -X GET http://localhost:5000/led
get()Â simply returns, on line (13), the global state variable:
def get(self):
""" Handles HTTP GET requests to return current LED state."""
return state # (13)
Flask-RESTful returns JSON responses to clients, and that's why we return the state variable. In Python, state is a dictionary structure that can be mapped directly into a JSON format. We saw the following JSON example previously when we make a GET request using curl:
{ "level": 50 }
This class-as-a-resource (for example, LEDControl) and method-to-HTTP-method mapping (for example, LEDControl.get()) is an example of how the Flask-RESTful extension makes RESTful API development...