For this challenge we'll be creating a HTTP notification system. A server (or set of servers) will keep track of topics ->
subscribers where a topic is a string and a subscriber is an HTTP endpoint. When a message is published on a topic, it
should be forwarded to all subscriber endpoints.
-
URL
/publish/:id - eg. http://127.0.0.1:8000/publish/topic1 /subscribe/:id - eg. http://127.0.0.1:8000/subscribe/topic1 -
Method:
POST -
Data Params for Subscribe
{ "url": "http://localhost:9000/test1" } -
Data Params for Publish
{ "message": "Hello" } -
Success Response:
- Code: 200
Content:Object
- Code: 200
-
Error Response:
- Code: 404 NOT FOUND
Content:Object
OR
- Code: 502 BAD GATEWAY
Content:{ status: 'Bad Gateway', message: 'Something went wrong' }
- Code: 404 NOT FOUND
-
Sample Call:
curl -X POST -H "Content-Type: application/json" -d '{ "url": "http://localhost:9000/test1"}' http://localhost:8000/subscribe/topic1 curl -X POST -H "Content-Type: application/json" -d '{ "url": "http://localhost:9000/test2"}' http://localhost:8000/subscribe/topic1 curl -X POST -H "Content-Type: application/json" -d '{"message": "hello"}' http://localhost:8000/publish/topic1
Project logs are created automatically into logs folder in these directories [publisher, subscriber]