Skip to content

donniewa/DevSeries-Backend-Flask

 
 

Repository files navigation

Contributors Forks Issues MIT License LinkedIn

Backend Flask Server

This is a simple hello world type OOP Flask application that can be used as a template for multiple uses.

Two endpoints with calls to a separate class returning JSON data to client.

Features:

  • Docker enabled
  • Flask v2.0.2
  • Simple OOP
  • 2 defined endpoints

Installation

Prerequisite for Python Flask Server

  • To do development through Docker only:
  • To do development outside of Docker containers:

Downloading this code from this repo

  1. Create a directory to save the code:
    mkdir Workspace
    cd Workspace
    
  2. Download this repo:
    git clone https://github.com/spaceshiptrip/DevSeries-Backend-Flask.git
    

Build and Execute

  • Change to the project directory
    cd DevSeries-Backend-Flask
    

Building and Running with Docker

Note: This is not necessary if you are not using Docker.

  • Build the docker container:

    docker build -t be:dev .
    
  • Run the app through the container:

    docker run -it --rm -v $(PWD):/app -p 5000:5000 -e CHOKIDAR_USEPOLLING=true --name be --rm be:dev
    

Non Dockerized Version

  • Pre-requisites:

    • Python 3
    • Pip 3
  • Optional to run in virtual env

    • Run the command to get into the virtual env
      source bin/activate
      
    • If errors are seen, run the command:
      rm -fr ./bin
      
      And install the virtualenv through the docs
  • Build the server

    pip3 install -r requirements.txt
    
  • Run the server

    python3 app.py
    

Post Startup

Test server response

Test with either cURL commands:

  • cURL (Windows MacOS)
    curl http://localhost:5000/getSomeData
    curl http://localhost:5000/getSomeDataFromFile
    

Stopping Server

  • Dockerized version
    • Open a terminal prompt
    • If you used the run command listed above:
      docker stop be
      
    • Replace be if you chose another name which can be found for port 5000:
      docker ps
      
  • Non Dockerized version
    • In the terminal running the server, press <CTRL>-c

About

Simple Flask backend JSON Server

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 99.6%
  • JavaScript 0.1%
  • C 0.1%
  • CSS 0.1%
  • Shell 0.1%
  • PowerShell 0.0%