New binding to receive POST data from a remote client

I am working on a new binding. Unlike most bindings which implement a web client that makes GET requests to fetch data from another system, this one would need to implement a web server to receive data via POSTs from the other system. My idea would be to add an applet to the OH core main web server, with a binding specific unique url, and have the OH core take any data sent by POST to that url and forward it to the binding for processing in its things and channels. => Is that possible?

1 Like

IIRC we have discuss that before (either when the HTTP or the mail binding was introduced) and the decision was that external systems should use the REST API. I don’t have the discussion at hand, but I believe it can be found on GitHUB.

Isn’t there already a binding that kind of does this already? [webhook] New, very simple binding for listening incomming http requests It only supports GET because most of the time if you have an IoT device that can send data through HTTP, it does so through GET with arguments instead of PUT or POST.

I wasn’t part of that discussion @J-N-K mentions (I don’t think) but I agree with the outcome. Is there a specific situation where you have a device or system that can send POST requests but it can’t be configured to support OH’s already existing API?

Regarding mail there was a (short) discussion in [smtp-action] port mail action to openhab2-addons · Issue #4915 · openhab/openhab-addons · GitHub because of but I’m pretty sure there was larger discussion regarding HTTP and the REST API.

I have 2 devices where a POST receiver could be used, but I have no control over the format of their data. Thus I can never have them directly use the OH REST API. I’m forced to have an intermediate server that receives the data, reformats it, and sends it on to OH. It would be helpful to have a way for OH to directly receive the data with a mechanism to reformat as needed.

The external system delivers its data by POST with a customise Json payload. There is no way to change the external payload structure, and certainly no way to force it to use OH Rest semantics. It needs a binding to receive the POST Json and translate it into OH things and channels.

1 Like

Hi, I am the author of [webhook] New, very simple binding for listening incomming http requests

To be honest - it do support POST/GET/PUT methods already :slight_smile: , though some of the not tested much as I didn’t needed.

Within my binding you simply create a thing which channels are being triggered by http requests directed to openhab instance.


1 Like

Does it work with OH4?

As soon as I migrate my personal instance to OH4 - it will be. Binding is simple enough to don’t cause major issue in adapting to OH4.

I use Piotr’s binding with OH4 and it works well so far.

FWIW I was not asking about any existing bindings. Rather I was asking about the possibility, in the binding which I am writing, to add a servlet to the OH core HTTP server, that can receive incoming data from a subsystem, and forward that data to the binding. I guess the answer is”no”. So I shall have to implement my own HTTP server within the binding, and do it the ‘hard way’…

Yes, you can deploy servlet into openhab http container under specific path. In fact, my binding uses this possibility.

Also,.you can describe my binding in a following way:

I use my binding to integrate openhab with an intercom which can notify about its states changes via http requests. You can configure the url it calls but not the http request structure itself, like Json data it posts. So intercom calls a specific url in openhab which is an url mapped to the servlet in my binding, the binding is configurable to understand the http call, it can parse the Json and passed it’s data interpretation into bindings things and channels.

I looked at your code, and I shall probably do something similar. Thanks for tip! :slight_smile:

Depending on complexity and shape of received data you might go also with custom rest resource. In such case some of content type negotiation and mapping to java objects might be provided for you. However, in such case you have to bridge binding and rest layer on your own.

1 Like