Programming a Flask API
This chapter aims to control our robot with Mycroft. To do so, we need to give our robot some way to receive commands from other systems. An Application Programming Interface (API) on a server lets us decouple systems like this to send commands across the network to another and receive a response. The Flask system is ideally suited to building this.
Web-based APIs have endpoints that other systems make their requests to and roughly map to functions or methods in a Python module. As you'll see, we map our API endpoints directly to functions in the Python robot_modes
module.
Before we get into building much, let's look at the design of this thing – it will also reveal how Mycroft works.
Overview of Mycroft controlling the robot
The following diagram shows how a user controls a robot via Mycroft:
The diagram in Figure 15.4 shows how data flows in this system...