Skip to content

Commit 4e33f6e

Browse files
committed
code refactor, readme, docker, tests
1 parent f44384d commit 4e33f6e

File tree

11 files changed

+301
-306
lines changed

11 files changed

+301
-306
lines changed

.gitignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
flask/
22
*.pyc
33
dev
4-
node_modules
5-
app/database.db
6-
app/build
4+
api/apidata.db
75
yarn.lock
86
yarn-error.log
97
*.psd

Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM python:3.8
2+
3+
ENV FLASK_APP run.py
4+
5+
COPY run.py requirements.txt ./
6+
7+
RUN pip install -r requirements.txt
8+
9+
CMD ["run:app", "flask shell"]

README.md

Lines changed: 101 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,101 @@
1-
# api-server-flask
1+
## api-server-flask
2+
3+
`api-server-flask` is a boilerplate starter template designed to help you quickstart your Flask based REST API server development. It has all the ready-to-use bare minimum essentials.
4+
5+
6+
## Features
7+
8+
- APIs: Signup, Login with (email, password), Logout, Edit User
9+
- SQLAlchemy + SQLite
10+
- Configs
11+
- Requirements
12+
- Tests: SignUp, Login
13+
14+
15+
## Table of Contents
16+
17+
1. [Getting Started](#getting-started)
18+
2. [Project Structure](#project-structure)
19+
3. [Modules](#modules)
20+
4. [Testing](#testing)
21+
22+
23+
## Getting Started
24+
25+
clone the project
26+
27+
```bash
28+
$ git clone https://github.com/app-generator/api-server-flask.git
29+
$ cd api-server-flask
30+
```
31+
32+
create virtual environment using python3 and activate it (keep it outside our project directory)
33+
34+
```bash
35+
$ python3 -m venv /path/to/your/virtual/environment
36+
$ source <path/to/venv>/bin/activate
37+
```
38+
39+
install dependencies in virtualenv
40+
41+
```bash
42+
$ pip install -r requirements.txt
43+
```
44+
45+
setup `flask` command for our app
46+
47+
```bash
48+
$ export FLASK_APP=run.py
49+
$ export FLASK_ENV=development
50+
```
51+
52+
initialize database, check `run.py` for shell context
53+
54+
```bash
55+
$ flask shell
56+
$ db.create_all()
57+
```
58+
59+
start test APIs server at `localhost:5000`
60+
61+
```bash
62+
$ python run.py
63+
```
64+
or
65+
```bash
66+
$ flask run
67+
```
68+
69+
use `flask-restx`' swagger dashboard to test APIs, or alternatively use `postman`
70+
71+
72+
## Project Structure
73+
74+
```bash
75+
api-server-flask/
76+
├── api
77+
│   ├── config.py
78+
│   ├── __init__.py
79+
│   ├── models.py
80+
│   └── routes.py
81+
├── Dockerfile
82+
├── README.md
83+
├── requirements.txt
84+
├── run.py
85+
└── tests.py
86+
```
87+
88+
89+
## Modules
90+
91+
This application uses the following modules
92+
93+
- Flask==1.1.4
94+
- flask-restx==0.4.0
95+
- Flask-JWT-Extended
96+
- pytest
97+
98+
99+
## Testing
100+
101+
Run tests using `pytest tests.py`

api/__init__.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,15 @@
33
Copyright (c) 2019 - present AppSeed.us
44
"""
55

6-
import os
7-
import re
8-
from datetime import datetime, timedelta, timezone
9-
10-
from flask import Flask, request, jsonify, make_response
11-
from flask_jwt_extended import JWTManager, jwt_required, get_jwt, create_access_token, get_jwt_identity
12-
from flask_restx import Api, Resource, marshal, fields, abort
13-
from flask_sqlalchemy import SQLAlchemy
14-
from werkzeug.security import generate_password_hash, check_password_hash
6+
from flask import Flask
157

8+
from .routes import rest_api, jwt
9+
from .models import db
1610

1711
app = Flask(__name__)
1812

19-
app.config.from_object('api.config.Config')
13+
app.config.from_object('api.config.BaseConfig')
2014

21-
db = SQLAlchemy(app)
22-
api = Api(app)
23-
jwt = JWTManager(app)
15+
db.init_app(app)
16+
rest_api.init_app(app)
17+
jwt.init_app(app)

api/app.py

Lines changed: 0 additions & 224 deletions
This file was deleted.

0 commit comments

Comments
 (0)