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

Choosing the desired representation

As in HTTP, CoAP supports RESTful interfaces. This means that the same resource can be represented in different ways, based on the preferences of the client. We will create a momentary resource that returns all momentary values when called. While the previous resources only support plain text responses, the momentary resource will support XML and JSON as well. The actual representation will be chosen based on the Accept header provided by the client. If no Accept header is provided, plain text will be returned by default:

this.momentaryResource = this.coapEndpoint.Register("/Momentary", (req, resp) => { if (req.IsAcceptable(Xml.ContentFormatCode)) this.ReturnMomentaryAsXml(req, resp); else if (req.IsAcceptable(Json.ContentFormatCode)) ...

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