Skip to content

manuelcoca/sample-python-flask-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Todo API

This project is a simple Todo API built with Flask, following a clean architecture approach. It includes endpoints to create, read, update, and delete todo items:

GET /api/todo/<int:todo_id>: Retrieve a todo item by ID.

POST /api/todo: Create a new todo item.

PUT /api/todo/<int:todo_id>: Update an existing todo item.

DELETE /api/todo/<int:todo_id>: Delete a todo item by ID.

Getting Started

Prerequisites

  • Docker
  • Python 3.7+
  • pip (Python package installer)

Installation

  1. Clone the repository:

    git clone [email protected]:manuel-io/sample-python-flask-api.git
    cd sample-python-flask-api
  2. Create and activate a virtual environment:

    python -m venv venv
    
    # Activate env on MacOS/Linux
    source venv/bin/activate
    
    # On Windows use
    venv\Scripts\activate
  3. Install the dependencies:

    pip install -r requirements.txt
  4. Set up environment variables:

    # For local development
    FLASK_APP=run.py
    FLASK_ENV=development
    DATABASE_URL=sqlite:///database.db
    API_URL=http://127.0.0.1:5000/api

Running the Project

Run locally

python run.py

Serve a production ready version locally

gunicorn --bind 0.0.0.0:8000 wsgi:app

The API will be available at http://127.0.0.1:8000/api and Swagger UI will be available at http://127.0.0.1:8000/api/swagger.

Run the application using Docker

docker build -t todo-api .
docker run -d -p 8000:8000 --name todo-api-container todo-api

The API will be available at http://127.0.0.1:8000/api and Swagger UI will be available at http://127.0.0.1:8000/api/swagger.

Running Tests

Unit Tests

To run unit tests, use the following command:

python -m unittest discover -s tests/unit

Integration Tests

To run integration tests, use the following command:

python -m unittest discover -s tests/integration

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

A boilerplate for flask REST API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published