This project is a REST API for a blogs website, developed using FastAPI. It incorporates modern development practices and tools to ensure robust and efficient performance.
- Poetry: Manages dependencies and virtual environments.
- SQLAlchemy ORM: Provides seamless interaction with the database.
- FastAPI: Powers the REST API endpoints.
- Status Codes and HTTPExceptions: Manages responses and errors.
- Repository Design Pattern: Abstracts data access logic for better separation of concerns.
- Routes: Organizes API routes for various functionalities.
- JWT: Implements JSON Web Tokens for secure authentication.
- OAuth2: Integrates OAuth2 for enhanced authentication and third-party service support.
- Async I/O: Utilizes asynchronous programming for improved performance.
- Docker: Containers the application for consistent environments across development and production.
- Pytest: Facilitates writing and executing tests.
- Mock DB: Uses a mock database for initial test cases.
- Database Engine: Transitioned from SQLite to PostgreSQL for advanced features and improved performance.
- Database Management Tool: Integrated
adminpgfor managing and viewing the PostgreSQL database.
- Structure the project
- Database Migration Tool: Continue using Alembic for migrations.
- Separate Databases: Maintain and manage separate databases for production and testing environments.
- Comprehensive Unit Tests: Develop more unit tests using the test database.
-
Clone the repository:
git clone https://github.com/MohanadGad38/Blog-with-jwt-unit-testing.git
-
Navigate to the project directory:
cd Blog-with-jwt-unit-testing
In the fast-api folder, you must create two environment files before running the project:
-
database_mangement.envPGADMIN_DEFAULT_EMAIL="test@gmail.com" PGADMIN_DEFAULT_PASSWORD="test"
-
database.envPOSTGRES_USER="MM" POSTGRES_PASSWORD="1G" POSTGRES_DB=blog
-
Set up the databases:
- Ensure PostgreSQL is running.
- Create the
blogdatabase:CREATE DATABASE blog;
- Configure the database URLs in your
.envfile.
-
Run the application:
docker-compose up
-
Install dependencies if you want to run it without docker but you must run database:
poetry install
Once the application is running, you can access the API at:
http://localhost:8000