This is a simple Flask app that provides a pastebin-like functionality using a REST API. It uses SQLite as the database and can be easily containerized with Docker.
To run the application, follow these steps:
- Install Python 3 and pip on your system.
- Clone the repository:
git clone https://github.com/SwanVods/flask-pastebin-app.git
- Create a virtual environment:
python3 -m venv venv
- Activate the virtual environment:
source venv/bin/activate
- Install the dependencies:
pip install -r requirements.txt
- Initialize the database :
flask db init
- Start migration:
flask db migrate
- Create the database:
flask db upgrade
- Start the server:
or you may use docker to run the application:
flask run
docker-compose up
- The server should now be running on
http://localhost:5000
To test the application, run the following command:
python -m unittest test_views.py
The following API endpoints are available:
Endpoint: GET /notes
Response:
[
{
"id": 1,
"text": "Some public text",
"visibility": true,
"created_at": "2023-02-17T10:30:00",
"updated_at": "2023-02-17T10:30:00"
},
{
"id": 2,
"text": "More public text",
"visibility": true,
"created_at": "2023-02-17T10:31:00",
"updated_at": "2023-02-17T10:31:00"
}
]
Endpoint: GET /notes/<note_id>
Response:
{
"id": 1,
"text": "Some text to paste",
"visibility": true,
"created_at": "2023-02-17T10:30:00",
"updated_at": "2023-02-17T10:30:00"
}
Endpoint: POST /notes
Request body:
{
"text": "Some text to paste",
"visibility": true
}
Response:
{
"id": 1,
"text": "Some text to paste",
"visibility": true,
"created_at": "2023-02-17T10:30:00",
"updated_at": "2023-02-17T10:30:00"
}
Endpoint: PUT /notes/<note_id>
Request body:
{
"text": "Updated text",
"visibility": false
}
Response:
{
"id": 1,
"text": "Updated text",
"visibility": false,
"created_at": "2023-02-17T10:30:00",
"updated_at": "2023-02-17T10:31:00"
}
Endpoint: DELETE /notes/<note_id>
Response:
{
"message": "Note deleted successfully"
}
The application follows a simple 3-tier architecture, consisting of presentation layer, business logic layer, and data storage layer. Below is a brief explanation of each component, libraries, dependencies, and tools used in the project.
Presentation Layer:
- Flask (Python Web Framework)
- Flask-RESTful (for building RESTful APIs)
- Werkzeug (for handling HTTP requests and responses)
Business Logic Layer:
- SQLite (as a database management system)
- SQLAlchemy (for object-relational mapping)
- Flask-Migrate (for handling database migrations)
Data Storage Layer:
- SQLite (as a database management system)
Dependencies:
- Flask
- SQLAlchemy
- Flask-Migrate
- Werkzeug
Tools:
- Docker (for containerizing the application)
- Unittest (for testing the application)
- Coverage (for measuring test coverage)
The architecture is designed in such a way that the presentation layer is separated from the business logic layer, and the business logic layer is separated from the data storage layer. The presentation layer (Flask) communicates with the business logic layer through a set of RESTful APIs. The business logic layer (SQLAlchemy) communicates with the data storage layer (SQLite) to persist data.
- Add authentication and authorization
- Implement input validation and sanitization to prevent injection attacks or malicious user input.
- Add support for other databases or data stores, such as MongoDB or AWS DynamoDB.
- Implement rate limiting to prevent abuse or overuse of the API.
- Implement testing for edge cases and scenarios that may not be covered in the current test suite.