Backend JSON API for Parity App
Parity is a text summarization and analytics platform that works on top of the messaging systems used internally at CERN. As will be demonstrated in the demo, they can also be applied outside of CERN, considering that they are integrated with Mattermost and Slack (primarily).
- 🐍 Python - Python 3 came out with asynchronous IO features, which will allow us to take greater advantage of concurrency and serve more requests for a given server.
- 🐋 Docker - Containerization and easy development/production environment bootstrapping
Make sure to have Docker and Docker-Compose installed. Then, follow through the following steps:
cd
to the base of the project directory- Rename
backend_sample.env
tobackend.env
- Fill in the appropriate information in both
backend.env
- Run
docker-compose build
- Run
docker-compose up
and now, you should be able to access the API routes at the localhost or whatever hostname your copy of Docker is working on! - To shut containers down, run
docker-compose down
The API routes are accessible under the hostname/api/
URL namespace. Output is in JSON format.
An access token can be obtained by hitting the '/auth' route. Subsequent routes needing the user being logged in, can be accessed by providing an Authorization header with the value Bearer <token>
.
Responses have the structure {status, data, message, errors}
, where the errors
prop is provided for ONLY whenever the status
denotes an HTTP error status. (>=400 status codes). Responses will be nested under the data
prop
/auth
POST /
- Login a user- Request:
{username, password}
- Response:
{token, channels: [{id, name}...], pulse: [{rate, time}...]}
- Request:
/stats
GET /pulse
- Get the activity pulse based on all channels the user is in- Response:
[{rate, time}...]
rate
is a float between [0,1] inclusivetime
is a string that could be passed to a Javascript Date constructor
- Response:
GET /pulse/{channels_id}
- Get the activity pulse of a channel based on the posts- Response:
[{rate, time}...]
rate
is a float between [0,1] inclusivetime
is a string that could be passed to a Javascript Date constructor
- Response:
GET /most_active/{channel_id}
- Get the most active users of a specific channel- Response:
[...]
- a list of strings
- Response:
GET /hot_topics/{channel_id}
- Get the "hot topics" of a channel- Response:
[...]
- a list of strings
- Response:
GET /representative_messages/{channel_id}
- Get past day's representative messages for the entire channel- Response:
[{username, message}]
- Response:
POST /representative_messages/{channel_id}
- Request:
{time}
time
must be an ISO string
- Response:
[{username, message}]
- Request:
GET /summary/{channel_id}
- Get past day's summary for the entire channel- Response:
{summary}
- Response:
POST /summary/{channel_id}
- Request:
{time}
time
must be an ISO string
- Response:
{summary}
- Request: