The actuator project (ActuatorHttp in the GitHub repository) also needs a /Momentary resource that returns the current state of the output in XML or JSON. The implementation is similar to that of the sensor, so it's straightforward to do. But we also need a way to control the output. We do that by adding a /Set resource. Since we will call asynchronous methods, we take this opportunity to add this resource as an asynchronous POST resource. This means we must explicitly handle errors and exceptions, as well as explicitly sending the response when it is ready:
this.httpServer.Register("/Set", null, async (req, resp) => { try { // Process resource here resp.SendResponse(); // Sends response. } catch (Exception ex) { resp.SendResponse(ex); // Sends error response....