Giter Site home page Giter Site logo

chang2358 / api-server-flask Goto Github PK

View Code? Open in Web Editor NEW

This project forked from app-generator/api-server-flask

0.0 0.0 0.0 60 KB

Flask API Server - Open-Source API Server | AppSeed

Home Page: https://appseed.us/boilerplate-code/

License: Other

Python 98.15% Dockerfile 1.85%

api-server-flask's Introduction

Simple Flask API Boilerplate enhanced with JWT authentication, OAuth via GitHub, SqlAlchemy, SQLite persistence, and deployment scripts via Docker. It has all the ready-to-use bare minimum essentials.

  • ๐Ÿ‘‰ Support via Discord & Email provided by AppSeed.

Features:

  • โœ… Up-to-date dependencies
  • โœ… API Definition - the unified API structure implemented by this server
  • โœ… API powered by Flask-restX
  • โœ… JWT Authentication (login, logout, register) via Flask-jwt_extended
  • ๐Ÿ†• OAuth for Github
  • โœ… Docker, Unitary tests

Can be used with other React Starters for a complete Full-Stack experience:

React Node JS Berry React Node Soft Dashboard React Node Horizon
React Node JS Berry React Node Soft Dashboard React Node Horizon

Flask API Server - Open-source Flask Starter provided by AppSeed.


โœจ Quick Start in Docker

Get the code

$ git clone https://github.com/app-generator/api-server-flask.git
$ cd api-server-flask

Start the app in Docker

$ docker-compose up --build  

The API server will start using the PORT 5000.


โœจ Table of Contents

  1. Getting Started
  2. Project Structure
  3. Modules
  4. Testing

โœจ How to use the code

Step #1 - Clone the project

$ git clone https://github.com/app-generator/api-server-flask.git
$ cd api-server-flask

Step #2 - create virtual environment using python3 and activate it (keep it outside our project directory)

$ # Virtualenv modules installation (Unix based systems)
$ virtualenv env
$ source env/bin/activate
$
$ # Virtualenv modules installation (Windows based systems)
$ # virtualenv env
$ # .\env\Scripts\activate

Step #3 - Install dependencies in virtualenv

$ pip install -r requirements.txt

Step #4 - setup flask command for our app

$ export FLASK_APP=run.py
$ export FLASK_ENV=development

For Windows-based systems

$ (Windows CMD) set FLASK_APP=run.py
$ (Windows CMD) set FLASK_ENV=development
$
$ (Powershell) $env:FLASK_APP = ".\run.py"
$ (Powershell) $env:FLASK_ENV = "development"

Step #5 - Create a new .env file using sample env.sample

The meaning of each variable can be found below:

  • DEBUG: if True the app runs in develoment mode
    • For production value False should be used
  • SECRET_KEY: used in assets management
  • GITHUB_CLIENT_ID: For GitHub social login
  • GITHUB_SECRET_KEY: For GitHub social login

Step #6 - start test APIs server at localhost:5000

$ flask run

Use the API via POSTMAN or Swagger Dashboard.

Flask API Server - Swagger Dashboard.


โœจ Project Structure

api-server-flask/
โ”œโ”€โ”€ api
โ”‚ย ย  โ”œโ”€โ”€ config.py
โ”‚ย ย  โ”œโ”€โ”€ __init__.py
โ”‚ย ย  โ”œโ”€โ”€ models.py
โ”‚ย ย  โ””โ”€โ”€ routes.py
โ”œโ”€โ”€ Dockerfile
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ requirements.txt
โ”œโ”€โ”€ run.py
โ””โ”€โ”€ tests.py

โœจ API

For a fast set up, use this POSTMAN file: api_sample

Register - api/users/register (POST request)

POST api/users/register
Content-Type: application/json

{
    "username":"test",
    "password":"pass", 
    "email":"[email protected]"
}

Login - api/users/login (POST request)

POST /api/users/login
Content-Type: application/json

{
    "password":"pass", 
    "email":"[email protected]"
}

Logout - api/users/logout (POST request)

POST api/users/logout
Content-Type: application/json
authorization: JWT_TOKEN (returned by Login request)

{
    "token":"JWT_TOKEN"
}

โœจ Testing

Run tests using pytest tests.py



Flask API Server - provided by AppSeed

api-server-flask's People

Contributors

app-generator avatar ksh7 avatar mominur-helios 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.