This API, built with Flask, enables user registration, friend management, and note exchange. It features an RBAC (Role-Based Access Control) system for multi-tier administrators with varying privileges. The database setup includes SQLite3 for unit tests and MariaDB for production, environment settings are managed via a config.toml file.
- User Registration: Register new users.
- Friend Management: Add and manage friends.
- Note Exchange: Exchange notes between users.
- RBAC System: Multi-tier admin roles with different access levels.
- Testing: Uses SQLite3 in-memory database for unit tests.
- Database: Utilizes MariaDB for production environments.
- Configuration: Managed via config.toml.
- Documentation: OpenAPI docs available courtesy of Swagger and Redoc.
- Install MariaDB from the official website.
- Create a database and a user:
Update
mariadb -u root -p CREATE DATABASE users; CREATE USER 'user'@'localhost' IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON users.* TO 'user'@'localhost'; FLUSH PRIVILEGES; EXIT;
config.toml
if you use different credentials.
-
Navigate to the
note_exchange_api/
folder and create a virtual environment:cd note_exchange_api python3 -m venv venv source venv/bin/activate
-
Install dependencies:
pip install -r requirements.txt
-
Initialize the database:
python build_database.py
-
Start the development server:
python run_app.py
-
Access the home page at
http://127.0.0.1:8000
. API documentation is available athttp://127.0.0.1:8000/api/docs
.
-
Run the tests:
python run_unit_tests.py
-
To see unit test coverage:
python run_coverage_tests.py
-
Download and install Postman from the official website.
-
Create a new request in Postman:
- Set the method (GET, POST, PUT, DELETE) and URL according to your API endpoints.
- Add necessary headers (e.g.,
Content-Type: application/json
). - Include the request body if needed (e.g., JSON data for POST requests).
- For protected endpoints, provide the Bearer token JWT in the
Authorization
header:Authorization: Bearer <your_jwt_token>
-
Send the request and view the response:
- Use Postman’s interface to send requests and view server responses, making it easier to test and debug the API.
This project is licensed under the MIT License.