A Python single-chat-room server using Websocket with MongoDB as the database
- Create an .env.docker file and add the values that need to be overwritten in
main/config.py
. For example:
MONGO_URI=mongodb://mongodb:27017
- Spin up all service using docker-compose
docker-compose up --build
- Create a virtual environment:
python3 -m venv venv
source venv/bin/activate
- Install dependencies:
pip install -r requirements.txt
- Create an .env file and add the values that need to be overwritten in
main/config.py
. For example:
MONGO_URI=mongodb://localhost:27017
- Start the server locally (listening on 8000)
./start_server.sh
or
uvicorn main:app --port 8000 --reload
API documentation could be found at http://localhost:8000/redoc
-
Install API testing tool Postman
-
Import
python_chat_server.postman_collection.json
in Postman. Instruction can be found here -
Create a user using POST /auth. Response should look like
{
"id": "{{YOUR_USER_ID}}",
"name": "Hiep"
}
- Using the id to connect to chat server. From your terminal
$ wscat --connect ws://localhost:8000/chat/{{YOUR_USER_ID}}
-
Repeat step 4 and 5 to have multiple users in your chat room (You should have multiple terminal tab open)
-
Start sending chat message in
wscat
console and expect the message is sent to other clients
- Create a virtual environment:
python3 -m venv venv
source venv/bin/activate
- Install dependencies:
pip install -r requirements.txt
- Run the tests
./run_tests.sh