O'Reilly logo

Mastering Internet of Things by Peter Waher

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding dynamic synchronous resources

To publish resources through our web server, we just call the Register method on the HttpServer object. We can choose between two methods: either we provide resource objects, inherited from the HttpResource class, such as the HttpSynchronousResource or HttpAsychronousResource classes, or we use lambda expressions or delegates for simple GET and POST resources.

We first demonstrate the latter to publish a resource for reading momentary sensor data. We provide a lambda expression, taking a request and response parameter. This expression will be executed when a GET method is received on the /Momentary resource:

this.httpServer.Register("/Momentary", (req, resp) => 
{ 
   ... 
}); 
The resource will be added as ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required