Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 82 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,98 @@
Simple Flask Todo App using SQLAlchemy and SQLite database.
# Flask Todo REST API

For styling [semantic-ui](https://semantic-ui.com/) is used.
> Extended version of [patrickloeber/flask-todo](https://github.com/patrickloeber/flask-todo) with a full REST API for task management.

### Setup
Create project with virtual environment
## Original Project

```console
$ mkdir myproject
$ cd myproject
$ python3 -m venv venv
This project is built on top of the [Simple Flask Todo App](https://github.com/patrickloeber/flask-todo) by Patrick Loeber. The original app provides a web interface for managing todo tasks.

## New Feature: REST API for Tasks

I added a complete REST API that allows external applications to manage tasks programmatically using JSON. This extends the original app's purpose by making task data accessible to any client (mobile apps, other servers, tools like Postman).

### API Endpoints

| Method | Endpoint | Description |
|--------|----------|-------------|
| GET | `/api/tasks` | Get all tasks |
| GET | `/api/tasks/<id>` | Get a specific task |
| POST | `/api/tasks` | Create a new task |
| PUT | `/api/tasks/<id>` | Update a task |
| DELETE | `/api/tasks/<id>` | Delete a task |

## Setup Instructions

### Prerequisites
- Python 3.8 or higher
- Git

### Installation

1. Clone the repository:
```bash
git clone https://github.com/YOUR_USERNAME/flask-todo.git
cd flask-todo
```

2. Create and activate a virtual environment:
```bash
python -m venv venv
venv\Scripts\activate # Windows
```

Activate it
```console
$ . venv/bin/activate
3. Install dependencies:
```bash
pip install flask flask-sqlalchemy pytest pytest-cov flasgger
```

or on Windows
```console
venv\Scripts\activate
4. Run the application:
```bash
python app.py
```

Install Flask
```console
$ pip install Flask
$ pip install Flask-SQLAlchemy
5. Open your browser:
- Web app: http://localhost:5000/
- API docs (Swagger): http://localhost:5000/apidocs/

## Running Tests

```bash
pytest test_api.py -v
```

### With Coverage Report

```bash
pytest test_api.py --cov=app --cov-report=term-missing -v
```

Set environment variables in terminal
```console
$ export FLASK_APP=app.py
$ export FLASK_ENV=development
## API Usage Examples

### Create a Task
```bash
curl -X POST http://localhost:5000/api/tasks \
-H "Content-Type: application/json" \
-d '{"title": "Buy groceries", "complete": false}'
```

### Get All Tasks
```bash
curl http://localhost:5000/api/tasks
```

or on Windows
```console
$ set FLASK_APP=app.py
$ set FLASK_ENV=development
### Update a Task
```bash
curl -X PUT http://localhost:5000/api/tasks/1 \
-H "Content-Type: application/json" \
-d '{"complete": true}'
```

Run the app
```console
$ flask run
### Delete a Task
```bash
curl -X DELETE http://localhost:5000/api/tasks/1
```

## Branch Information

- `master` — Original project by Patrick Loeber
- `feature/tasks-api` — My REST API additions
Loading