This repo contains a toy example for a notifications app. It has a backend written in Node, and a frontend created with Create React App.
The backend is a Node server, with two endpoints and a sqlite db. The server will check for the existence of the db on startup, and will create it with a notifications
table if it does not exist. Both run by default on localhost; as this is just an example project there is no option to configure different hosts or ports.
To start the backend server, from the root of the project run:
npm install
node app.js
To add a notification to the system, send a POST to http://localhost:8081/notifications
with the body below.
{
"source": "my source",
"type": "arbitrary",
"version": 0,
"data": {
"message": "This is a message",
"user": "user_id",
"event_timestamp": 1651497606
}
}
Each notification has a fixed set of metadata fields; in this toy example each has a timestamp
( generated by the db and indicating the ingestion time of the notification), a source
field (to indicate the origin server/service/etc.), and type
and version
fields.
The data field represents the data payload of the notification, and is an arbitrary json. In a productized version of this toy application, downstream consumers of these notifications would be type- and version-aware, and would use versioned schemas parse the json in the data field.
In this toy example, the UI consumer is not type or version aware, and just displays the arbitrary json in the data field. However, any valid JSON may be entered substituted for the value of the data
field above, and will be displayed correctly by the UI.
To get a list of all notifications in the system, send a GET to http://localhost:8081/notifications
. This will return a list of all notififcations, sorted by the timestamp
field. Sorting, filtering, pagination, etc. are not supported as this is not a productized example.
The frontend is a very minimal React app, When loaded, it displays the full list of all notifications in the db.
To start the front end (in development mode), from the root of the project run:
cd notifications-ui
npm install
npm start