Code Monkey home page Code Monkey logo

sockethook's Introduction

Sockethook

Deploy

Sockethook is a Webhook-to-WebSocket proxy written in Go. It's designed for building real-time applications around third-party APIs which provide Webhooks. Sockethook could for example be used to create a live feed of Github deployments or a real-time view of Shopify orders.

Usage

Sockethook is written in Go and can be installed by running

$ go get github.com/fabianlindfors/sockethook

The tool is started with

$ sockethook
INFO[0000] Sockethook is ready and listening at port 1234 โœ…

Sockethook is now ready to start receiving Webhooks! WebSockets can be connected through /socket followed by the endpoint to which you want to subscribe, for example: /socket/order/created. Any Webhook requests sent to /hook/order/created will now be broadcast to all subscribers listening to the specific endpoint.

The broadcasted message will be JSON encoded and contain information about the Webhook request. The following is an example message from a Shopify Webhook:

{
  "headers": {
    "Accept": "*\/*",
    "Accept-Encoding": "gzip;q=1.0,deflate;q=0.6,identity;q=0.3",
    "Connection": "close",
    "Content-Length": "4264",
    "Content-Type": "application\/json",
    "User-Agent": "Ruby",
    "X-Forwarded-For": "35.231.14.37",
    "X-Forwarded-Proto": "https",
    "X-Shopify-Hmac-Sha256": "wa5ZVAJPjbtr4Oj8xVnt\/jLWwfD9JdGFcdrjY4VgORQ=",
    "X-Shopify-Order-Id": "820982911946154508",
    "X-Shopify-Shop-Domain": "fabianlindfors.myshopify.com",
    "X-Shopify-Test": "true",
    "X-Shopify-Topic": "orders\/create"
  },
  "endpoint": "\/order\/created",
  "data": {
    "app_id": null,
    "billing_address": {
      "address1": "123 Billing Street",
      "address2": null,
      "city": "Billtown",
      "company": "My Company",
      "country": "United States",
      "country_code": "US",
      "first_name": "Bob",
      "last_name": "Biller",
      "latitude": null,
      "longitude": null,
      "name": "Bob Biller",
      "phone": "555-555-BILL",
      "province": "Kentucky",
      "province_code": "KY",
      "zip": "K2P0B0"
    }
    ...
  }
}

If the request content type is JSON then the data field will contain the JSON body. Otherwise data will be a string of the body.

Command-line options

Two possible options can be passed to Sockethook, --port and --address. --port specifies which port at which to listen (default is 1234) and --address sets a specific address to bind to.

$ sockethook --port 8000
$ sockethook --address 127.0.0.1

Authentication

Sockethook doesn't include any authentication meaning all endpoints and sockets are publicly available by default. The recommended way to add authentication is to use a reverse proxy or similar, which lends a lot of flexibility. Examples include nginx, Caddy, and Traefik.

License

Sockethook is licensed under MIT.

sockethook's People

Contributors

corollari avatar fabianlindfors avatar nanobotz avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.