Skip to content

Instantly share code, notes, and snippets.

@jordangarcia
Created October 17, 2019 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jordangarcia/50e76dccdae9d09d832e3d9695de6238 to your computer and use it in GitHub Desktop.
Save jordangarcia/50e76dccdae9d09d832e3d9695de6238 to your computer and use it in GitHub Desktop.

Technical Question

Create a simple pub/sub system using webhooks. It will require you to create two servers, a publisher and a subscriber.

Publisher Server Requirements

  1. publish a payload to topic
  2. subscribe to a topic to receive payloads

POST /publish/{topic} body: {payload}

POST /subscribe/{topic}?callback_url={subscriberServerEndpoint}

Subscriber Server Requirements

GET /event // output

{topic:”foo”, “payload”: “this is the payload”}

Example using shell commands

$ ./start-producer.sh 8001
$ ./start-consumer.sh 8002
$ curl -X POST http://localhost:8001/subscribe/foo?callback=http://localhost:8002/event
$ curl -X POST -d '{"data": "hello"}' http://localhost:8001/publish/foo

then the subscriber server would print out what it received

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment