Fork me on GitHub

Web Socket Hook

Built by Factor.io and hosted on websockethook.io
Web Socket Hook is a bridge between web hooks and web sockets. You can connect to the service using a web socket client and register a web hook. On the other end you can POST messages to that web hook address, which will be received by your web socket client.

Take it for a spin

By opening this page you already initiated a new Web Socket connection to the server. You should see a green message "Web socket is open" to the right.

The initiation of a new web socket also registered a new random default web hook. You can see the list of registered webhooks on the right.

From the command line run the command from the "cURL Command" column in the "Registered Hooks" table.

You should see {"foo":"bar"} appear in the "Incoming Messages" table.

Pretty cool huh?

Now try to change the values in the --data value in the curl command.

Lastly, you can also set your own IDs.

This way you can create a web hook with a third party service and always listen on the same address, even if the web socket connection is restarted. It also allows multiple web socket connections to share the same web hook address. You can test this by opening two browser windows and registered a web-hook with the same address and POSTing data to it.

Registered Hooks:

ID cURL command
waiting...

Incoming messages:

Hook ID Message
waiting...

How does it work?

When a connection is established the service send a message similar to this.

{
  "type": "registered",
  "data": {
    "id": "31dd0a8df6dc6d1b",
    "url": "/hook/31dd0a8df6dc6d1b"
  }
}

which tells us that it created a web hook at the address /hook/31dd0a8df6dc6d1b and can receive HTTP POST messages.

Now you can perform a curl command to POST to this endpoint. When the POST occurs, the service will send another message over the web socket similar to this.

{
  "type": "hook",
  "id": "31dd0a8df6dc6d1b",
  "data": {
    "foo": "bar"
  }
}

You can also register a new web hook over the open web socket by sending a message like this.

{
  "type": "register",
  "id": "my_static_address"
}

And of course you can un-register this hook with this command

{
  "type": "unregister",
  "id": "my_static_address"
}

Why?

In Factor.io we have to listen for web hooks behind a firewall sometimes. For example, you can create a workflow that triggers a chef run on your servers every time code is merged in Github. But github needs to perform an HTTP POST (web hook) to trigger this workflow. Now the workflow just connects to this service and then registered it's public address with Github.

Disclaimer

No tests! This is currently only tested manually.