Coder Social home page Coder Social logo

fastapi-chat-server's Introduction

Python Chat Room

A Python single-chat-room server using Websocket with MongoDB as the database

Docker setup (Recommended)

Prerequisite

  1. Docker

Instruction

  1. 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
  1. Spin up all service using docker-compose
docker-compose up --build

Manual setup

Prerequisite

  1. Python3
  2. MongoDB

Instruction

  1. Create a virtual environment:
python3 -m venv venv
source venv/bin/activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Create an .env file and add the values that need to be overwritten in main/config.py. For example:
MONGO_URI=mongodb://localhost:27017
  1. 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

Test the app

  1. Install Websocket test client wscat (Nodejs is required)

  2. Install API testing tool Postman

  3. Import python_chat_server.postman_collection.json in Postman. Instruction can be found here

  4. Create a user using POST /auth. Response should look like

{
    "id": "{{YOUR_USER_ID}}",
    "name": "Hiep"
}
  1. Using the id to connect to chat server. From your terminal
$ wscat --connect ws://localhost:8000/chat/{{YOUR_USER_ID}}
  1. Repeat step 4 and 5 to have multiple users in your chat room (You should have multiple terminal tab open)

  2. Start sending chat message in wscat console and expect the message is sent to other clients

Integration tests

  1. Create a virtual environment:
python3 -m venv venv
source venv/bin/activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Run the tests
./run_tests.sh

fastapi-chat-server's People

Contributors

hoanghiep106 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.