Skip to content

Files

Failed to load latest commit information.

Latest commit

 

History

History

server

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Gachichat Backend

Environment variables

You can customize the application using environment variables

Variable Description Default value
Django settings
ALLOWED_HOSTS Comma separated values of hosts for django setting ALLOWED_HOSTS. Django docs 127.0.0.1,localhost
DEBUG Django docs False
TIME_ZONE Django docs UTC
Database settings
DATABASE_ENGINE Django database engine that will used for ORM django.db.backends.postgresql_psycopg2
DATABASE_NAME Your database name gachichat
DATABASE_HOST Your database host name 127.0.0.1
DATABASE_PORT DB port 5432
DATABASE_USER Username for DB auth postgres
DATABASE_PASSWORD Password for DB auth
Other settings
SECRET_KEY Secret key for hashing and encoding
USER_TOKEN_EXPIRING Count of seconds for JSON Web Token lifetime 604800

API

Users

POST /users/create

Create new user for chosen room

JSON POST Data:

room_id - Numeric value for id of the room for registration

password [optional] - Password for the room. If password is setted

Response:

{
    id: 26,
    token: 'yourAPItoken'
    first_name: 'maria'
    last_name: 'hart'
    created: 1557492563
    expired_in: 1558097363
}

GET /users/getMe

Get information of user

Headers:

{
    Authorization: 'yourAPItoken'
}

Response:

{
    id: 26
    first_name: 'maria'
    last_name: 'hart'
    created: 1557492563
}

Rooms

POST /rooms/create

Create random named room and user for this room

JSON POST Data:

password [optional] - Password for creating room. If you set it, your room will be private.

name [optional] - Name of the creating room. Default is random words.

description [optional] - Description of the creating room.

Response:

{
    user: {
        id: 26,
        token: 'yourAPItoken'
        first_name: 'maria'
        last_name: 'hart'
        created: 1557492563
        expired_in: 1558097363
    }
    room: {
        id: 10
        name: 'Soap_Laptop'
        description: ''
        link: ''
        created: 1557492563
        password: 'qwerty12+'
    }
}

GET /rooms/info

Get information of room

Headers:

{
    Authorization: 'yourAPItoken'
}

Response:

{
    id: 10
    name: 'Soap_Laptop'
    description: ''
    link: ''
    created: 1557492563
}

Messages

POST /messages/send

Send message to room

Headers:

{
    Authorization: 'yourAPItoken'
}

Response:

{
    id: 19
    text: 'Hello. This is text of message'
    created: 1557615906
    user: {
        id: 26,
        first_name: 'maria'
        last_name: 'hart'
        created: 1557492563
    }
}

GET /messages/get

Getting all or filtered messages

Headers:

{
    Authorization: 'yourAPItoken'
}

GET arguments:

offset [optional] - count of messages for offset

count [optional] - numeric value of count messages in response

Response:

[
    {
        id: 19
        text: 'Hello. This is text of message'
        created: 1557615906
        user: {
            id: 26,
            first_name: 'maria'
            last_name: 'hart'
            created: 1557492563
        }
    }
]

Installation

It's very easy. Follow the instructions:

Python and dependencies

  1. Install the Python interpreter using the batch manager of your operating system.
  2. Create virtual environment
$ virtualenv venv -p python3 --no-site-packages
Running virtualenv with interpreter /bin/python3
...
done
  1. Enter to virtual environment
$ source venv/bin/activate
  1. Install all dependencies using pip
(venv) $ pip install -r requirements.txt
Collecting...
...
Successfully installed...

PostgreSQL

  1. Install PostgreSQL using your package manager of your OS
  2. Run it like a daemon
$ systemctl start postgresql.service
  1. Open PostgreSQL console
$ sudo -u postgres psql postgres
  1. Create database
# create database gachichat owner postgres
  1. That is all. Just log out from postgres user by pressing CTRL + D

If you have difficulties with postgresql consult your operating system documentation

Migrations

After the previous two steps you need to enter again the virtual environment (step 3 in python) and apply all migrations

(venv) $ python manage.py migrate

Fin

That's all. You awesome. Just run

(venv) $ python manage.py runserver

And have fun!