Setup Documentation
Setup Documentation
Table of Contents
1. Running the Project in a Local Environment
○ Prerequisites
○ Steps to Set Up
○ Using Docker
○ Updating Dependencies
2. API Endpoints
○ Register User
○ Login User
○ Get User Profile by User ID
○ Get User Profile by Username
○ Logout User
3. Security Considerations
1. IDE Installation: Install an IDE suitable for Django development, such as VS Code or
PyCharm.
2. Python Installation: Install Python 3.12.0 or newer and set its PATH in the Environment
variables.
3. Virtual Environment Setup: Create and activate a virtual environment for the project.
Steps to Set Up
Create a Project Directory:
mkdir myproject
cd myproject
1. Install virtualenv:
pip install virtualenv
2. Create Virtual Environment:
virtualenv venv or
python -m venv venv
4. Install Django:
pip install django
6. Configure MongoDB: Update the MongoDB connection URI and database name in the
.env file. Adjust the collection name in models.py if necessary.
7. Apply Migrations:
python manage.py makemigrations
python manage.py migrate
○ http://127.0.0.1:8000/
○ http://localhost:8000/
Using Docker
1. Install Docker Desktop: Install Docker Desktop and start the Docker engine.
Updating Dependencies
To update package dependencies after code changes:
pip freeze > requirements.txt
This last command will generate the coverage report and update the .coverage file. But it can
only be done in the local setup.
API Endpoints
Register User
● Endpoint: /user/register_user
● Method: POST
Request Body:
json
{
"username": "alphanumeric",
"email": "emailId",
"password": "atleast 8 characters",
"first_name": "string",
"last_name": "string"
}
●
● Response Codes:
○ 201: User created successfully
○ 400: Bad Request
Login User
● Endpoint: /user/login
● Method: POST
Request Body:
json
{
"email": "user email",
"password": "user password"
}
Response Body:
json
{
"access_token": "jwt token",
"user_id": "user_id"
}
● Response Codes:
○ 200: Login successful, returns tokens
○ 401: Invalid credentials
● Endpoint: /user/user_profile/<user_id>
● Method: GET
● Header: “User-ID” : “user_id”
● Response Codes:
○ 200: User details retrieved successfully
○ 400: User not found
○ 400: Invalid request
● Endpoint: /user/user_profile/username/<username>
● Method: GET
● Header: “User-ID” : “user_id”
● Response Codes:
○ 200: User details retrieved successfully
○ 404: User not found
○ 400: Invalid request
Logout User
● Endpoint: /user/logout
● Method: POST
● Header: “User-ID” : “user_id”
● Response Codes:
○ 200: Successfully logged out
○ 400: Bad Request
● URL: http://localhost:8000/swagger/
● Method: GET
● Description: Details of every API can be accessed, tested, and reviewed with the help
of swagger documentation, which can be accessed with the provided URL.
Security Considerations
● JWT Token Usage: JWT tokens are securely stored in cookies to mitigate XSS attacks.
● CSRF Protection: CSRF tokens are utilized with strict same-site access and expiration
times to prevent CSRF attacks.
This document provides a comprehensive guide for setting up and using the Django project
locally and with Docker, along with details about available API endpoints and security measures.