Coder Social home page Coder Social logo

selfmadeselfpaidx / flask-backend-api-template Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nang-dev/flask-backend-api-template

0.0 0.0 0.0 1.68 MB

Template to turn locally running backend Python code into an API for Web Apps

License: MIT License

Python 84.08% Dockerfile 15.92%

flask-backend-api-template's Introduction

๐Ÿš€ Flask Backend API Project Template

When you have a Python project that runs locally but want to turn it into a webapp, you have to make it into an API. This is a template that takes care of this for you.

Put your backend code in /api, and add endpoints to call it in routes.py.

Put your frontend code in /frontend and call the flask endpoint, and voila - all done!

There might be some rough edges around this template, but it should give you an idea of what to do.

Project Template: Backend API

๐Ÿ› ๏ธ Directory Structure

   api                      # API related code
    โ”œโ”€โ”€ Dockerfile           # Dockerfile for the API
    โ”œโ”€โ”€ README.md            # README for the API
    โ”œโ”€โ”€ __init__.py          # API package initialization
    โ”œโ”€โ”€ app                  # Main application package
    โ”‚   โ”œโ”€โ”€ __init__.py      # App package initialization
    โ”‚   โ”œโ”€โ”€ config.py        # Configuration file
    โ”‚   โ”œโ”€โ”€ data
    โ”‚   โ”‚   โ””โ”€โ”€ database_service.py # Database service
    โ”‚   โ”œโ”€โ”€ health
    โ”‚   โ”‚   โ”œโ”€โ”€ __init__.py
    โ”‚   โ”‚   โ””โ”€โ”€ health_service.py # Health check service
    โ”‚   โ”œโ”€โ”€ routes.py        # Route definitions
    โ”‚   โ””โ”€โ”€ utils            # Utility functions and classes
    โ”œโ”€โ”€ main.py              # Main entry for running the API
    โ”œโ”€โ”€ requirements.txt     # Required Python packages
    โ”œโ”€โ”€ swagger.json         # Swagger specification
    โ””โ”€โ”€ tests                # Test package
        โ”œโ”€โ”€ __init__.py      # Test package initialization
        โ”œโ”€โ”€ conftest.py      # Pytest configuration
        โ””โ”€โ”€ test_routes.py   # Tests for the routes

๐Ÿงญ How To Run (Local)

  1. cd api
  2. pip install -r requirements.txt
  3. python app.py
  4. Trigger endpoints with:

    curl -X 'GET' \
    'http://127.0.0.1:8000/health' \
    -H 'accept: application/json'
  5. Run tests with: curl -X 'GET'
    'http://127.0.0.1:8000/health'
    -H 'accept: application/json'

    python -m pytest -p no:warnings

CI/CD + Dev Notes

Python Version and Code Style

  • Using Python 3.7 for development.
  • Code formatting is handled by black, a code formatter that enforces PEP 8 style guide.
  • Linting is done with flake8, which helps to identify coding errors and maintain code quality.

Pre-commit Hooks

  • The project uses pre-commit to manage and maintain pre-commit hooks.
  • Run pre-commit install to install pre-commit formatting and linting. This ensures that every commit adheres to the code style guide and passes linting checks.
  • You can manually run all pre-commit hooks on a repository with pre-commit run --all-files.

flask-backend-api-template's People

Contributors

nang-dev avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.