A simple RESTful API for managing blog posts and comments using Flask.
This Flask application provides a blog API that allows users to create and manage blog posts and add comments to existing posts. The application is built using Flask and SQLAlchemy and includes user authentication using JWT.
To run this application locally, follow these steps:
-
Clone the repository:
git clone git@github.com:ttsia/flask-rest-blog-example.git cd flask-rest-blog-example
-
Create a virtual environment (optional, but recommended):
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install the required packages:
pip install -r requirements.txt
-
Set the environment variables:
Rename the .env.example file to .env and provide the necessary configuration values.
-
Initialize the database:
flask db init flask db migrate
-
Start the application:
flask run
The API will be available at http://localhost:5000. Use your preferred API client (e.g., Postman, cURL) to interact with the API. API Documentation
-
Init DB:
flask db init flask db migrate
You can also run the application using Docker for easy deployment and isolation.
Make sure you have Docker installed on your system. Clone the repository and navigate to the project root directory. Build the Docker image and start the containers:
docker-compose build
docker-compose up
After docker-compose up
command, run:
docker-compose exec web flask db init
docker-compose exec web flask db migrate
The API will be available at http://localhost:5000.
To run the unit tests for this application, execute the following command:
pytest
This will run the test cases and display the test results.