Reader small image

You're reading from  Mastering Internet of Things

Product typeBook
Published inMar 2018
PublisherPackt
ISBN-139781788397483
Edition1st Edition
Right arrow
Author (1)
Peter Waher
Peter Waher
author image
Peter Waher

Peter Waher is the founder of Little Sister®, a standards-based distributed social network, based on the principles of edge computing, privacy & information ownership, for humans and machines. Currently, Peter advises companies on topics such as privacy, the IoT and Smart Cities. He has worked for 24 years with computers and device communication, including low-level development in assembler for resource-constrained devices to high-level system design and architecture. His award-winning applications has attracted global attention, and he has been invited to speak at prestigious events.
Read more about Peter Waher

Right arrow

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) => 
{ 
   ... 
}); 

Note

The resource will be added as a synchronous resource. This means that the response must be generated completely before returning from the expression. We don't have to worry about exceptions or explicitly sending the response. The web server will do that for us if we forget...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Mastering Internet of Things
Published in: Mar 2018Publisher: PacktISBN-13: 9781788397483

Author (1)

author image
Peter Waher

Peter Waher is the founder of Little Sister®, a standards-based distributed social network, based on the principles of edge computing, privacy & information ownership, for humans and machines. Currently, Peter advises companies on topics such as privacy, the IoT and Smart Cities. He has worked for 24 years with computers and device communication, including low-level development in assembler for resource-constrained devices to high-level system design and architecture. His award-winning applications has attracted global attention, and he has been invited to speak at prestigious events.
Read more about Peter Waher