Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[paho-dev] Binding MQTT to REST servers using Link: rel="mqtt"

I've been working quite a bit with RESTful webservices and MQTT recently. One annoying gap of REST interfaces is there's no clear / simple / natural way to work notifications into the paradigm. For example, consider this resource

This is very well behaved from a REST point of view. It can handle GET and PUT (and I think PATCH) requests to retrieve and modify state. However, if the state is modified, how does someone else know this in near real time? Well, MQTT is a natural solution, but the way a developer would know this is to "read the docs". Reading the docs kinda sucks if you can make it Just Work. 

For discussion, I'm proposing a rel="mqtt" Link type that can bind REST resources to an MQTT server. For example, if you look at that resource above:

$ curl --include
HTTP/1.1 200 OK
Date: Sat, 05 Jul 2014 14:36:37 GMT
Server: Apache/2.2.25 (Unix) DAV/2 PHP/5.2.16 mod_ssl/2.2.25 OpenSSL/0.9.8e-fips-rhel5 mod_fastcgi/2.4.6
Content-Length: 43
Access-Control-Allow-Headers: Content-Type
Link: <tcp://>; rel="mqtt"; payload=PUT; topic="basement/hue/1"
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, PUT, POST
Content-Type: application/json

     "on": true, 
     "rgb": "#FF0000"

The Link: header says that there's an associated MQTT resource available, that broadcasts updates (payload=PUT) in JSON (the default content-type) using the topic "basement/hue/1". Deeper documentation is available here:

And a really lousy diagram of what this looks like right here:

Your feedback is appreciated.


Back to the top