Skip to content

Commit 8c71e48

Browse files
authored
Merge pull request #6 from gitgik/develop
Develop
2 parents e70250d + e76043c commit 8c71e48

18 files changed

Lines changed: 119 additions & 126 deletions

README.md

Lines changed: 62 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,104 @@
11
# flask-rest-api [![Build Status](https://travis-ci.org/gitgik/flask-rest-api.svg?branch=master)](https://travis-ci.org/gitgik/flask-rest-api)
2-
A flask-driven restful API for Bucketlist interactions
32

3+
A flask-driven restful API for Bucketlist interactions
44

55
## Technologies used
6+
67
* **[Python3](https://www.python.org/downloads/)** - A programming language that lets you work more quickly (The universe loves speed!).
78
* **[Flask](flask.pocoo.org/)** - A microframework for Python based on Werkzeug, Jinja 2 and good intentions
89
* **[Virtualenv](https://virtualenv.pypa.io/en/stable/)** - A tool to create isolated virtual environments
910
* **[PostgreSQL](https://www.postgresql.org/download/)** – Postgres database offers many [advantages](https://www.postgresql.org/about/advantages/) over others.
1011
* Minor dependencies can be found in the requirements.txt file on the root folder.
1112

12-
1313
## Installation / Usage
14+
1415
* If you wish to run your own build, first ensure you have python3 globally installed in your computer. If not, you can get python3 [here](https://www.python.org).
1516
* After this, ensure you have installed virtualenv globally as well. If not, run this:
17+
18+
```bash
19+
pip install virtualenv
1620
```
17-
$ pip install virtualenv
18-
```
19-
* Git clone this repo to your PC
20-
```
21-
$ git clone git@github.com:gitgik/flask-rest-api.git
21+
22+
* Git clone this repo
23+
24+
```bash
25+
git clone git@github.com:gitgik/flask-rest-api.git
2226
```
2327

28+
* ### Dependencies
2429

25-
* #### Dependencies
26-
1. Cd into your the cloned repo as such:
27-
```
28-
$ cd flask-rest-api
29-
```
30+
1. Cd into your the cloned repo:
3031

31-
2. Create and fire up your virtual environment in python3:
32+
```bash
33+
cd flask-rest-api
3234
```
33-
$ virtualenv -p python3 venv
34-
$ pip install autoenv
35+
36+
2. Create and get into your virtual environment:
37+
38+
```bash
39+
virtualenv -p python3 venv
40+
source venv/bin/activate
3541
```
3642

37-
* #### Environment Variables
38-
Create a .env file and add the following:
39-
```
40-
source venv/bin/activate
41-
export SECRET="some-very-long-string-of-random-characters-CHANGE-TO-YOUR-LIKING"
42-
export APP_SETTINGS="development"
43-
export DATABASE_URL="postgresql://localhost/flask_api"
43+
* ### Environment Variables
44+
45+
Install [Dotenv](https://pypi.org/project/python-dotenv/) as follows:
46+
47+
```bash
48+
pip install python-dotenv
4449
```
4550

46-
Save the file. CD out of the directory and back in. `Autoenv` will automagically set the variables.
47-
We've now kept sensitive info from the outside world! 😄
51+
Create a .env file and add the following:
4852

49-
* #### Install your requirements
53+
```bash
54+
SECRET="some-very-long-string-of-random-characters-CHANGE-TO-YOUR-LIKING"
55+
APP_SETTINGS="development"
56+
DATABASE_URL="postgresql://localhost/flask_api"
5057
```
58+
59+
Dotenv will load your environment variables by reading the key-value pairs from the .env file.
60+
61+
* ### Install your requirements
62+
63+
```bash
5164
(venv)$ pip install -r requirements.txt
5265
```
5366

54-
* #### Migrations
55-
On your psql console, create your database:
56-
```
67+
* ### Database Migrations
68+
69+
Make sure your postgresql server is running. Then, on your psql console, create your database:
70+
71+
```bash
72+
$ psql -U postgres
5773
> CREATE DATABASE flask_api;
5874
```
59-
Then, make and apply your Migrations
60-
```
61-
(venv)$ python manage.py db init
6275

63-
(venv)$ python manage.py db migrate
64-
```
76+
In the project directory, make and apply your Migrations
77+
78+
```bash
79+
(venv)$ flask db init
6580
66-
And finally, migrate your migrations to persist on the DB
81+
(venv)$ flask db migrate
6782
```
68-
(venv)$ python manage.py db upgrade
83+
84+
And finally, migrate to persist them on the database
85+
86+
```bash
87+
(venv)$ flask db upgrade
6988
```
7089

71-
* #### Running It
90+
* ### Running the Server
91+
7292
On your terminal, run the server using this one simple command:
73-
```
93+
94+
```bash
7495
(venv)$ flask run
7596
```
97+
7698
You can now access the app on your local browser by using
77-
```
99+
100+
```bash
78101
http://localhost:5000/bucketlists/
79102
```
103+
80104
Or test creating bucketlists using Postman

app/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
from instance.config import app_config
1111

12+
from flask_migrate import Migrate, migrate
13+
1214
# For password hashing
1315
from flask_bcrypt import Bcrypt
1416

@@ -27,6 +29,8 @@ def create_app(config_name):
2729
app.config.from_object(app_config[config_name])
2830
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
2931
db.init_app(app)
32+
migrate = Migrate(db, app)
33+
migrate.init_app(app, db)
3034

3135
@app.route('/bucketlists/', methods=['POST', 'GET'])
3236
def bucketlists():

app/auth/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def post(self):
5252
if access_token:
5353
response = {
5454
'message': 'You logged in successfully.',
55-
'access_token': access_token.decode()
55+
'access_token': access_token
5656
}
5757
return make_response(jsonify(response)), 200
5858
else:

app/models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ def generate_token(self, user_id):
6161
def decode_token(token):
6262
"""Decode the access token from the Authorization header."""
6363
try:
64-
payload = jwt.decode(token, current_app.config.get('SECRET'))
64+
payload = jwt.decode(token, current_app.config.get(
65+
'SECRET'), algorithms=["HS256"])
6566
return payload['sub']
6667
except jwt.ExpiredSignatureError:
6768
return "Expired token. Please log in to get a new token"

habitat/instance/__init__.py

Whitespace-only changes.

habitat/instance/config.py

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

instance/config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
import os
2+
from dotenv import load_dotenv
3+
4+
# Load environment variables
5+
load_dotenv()
26

37

48
class Config(object):
@@ -12,6 +16,7 @@ class Config(object):
1216
class DevelopmentConfig(Config):
1317
"""Configurations for Development."""
1418
DEBUG = True
19+
SQLALCHEMY_TRACK_MODIFICATIONS = False
1520

1621

1722
class TestingConfig(Config):

manage.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,18 @@
22
import unittest
33
# class for handling a set of commands
44
from flask_script import Manager
5-
from flask_migrate import Migrate, MigrateCommand
65
from app import db, create_app
76

87
# initialize the app with all its configurations
98
app = create_app(config_name=os.getenv('APP_SETTINGS'))
10-
migrate = Migrate(app, db)
9+
1110
# create an instance of class that will handle our commands
1211
manager = Manager(app)
1312

14-
# Define the migration command to always be preceded by the word "db"
15-
# Example usage: python manage.py db init
16-
manager.add_command('db', MigrateCommand)
17-
18-
1913
# define our command for testing called "test"
2014
# Usage: python manage.py test
15+
16+
2117
@manager.command
2218
def test():
2319
"""Runs the unit tests without test coverage."""

requirements.txt

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,39 @@
1-
alembic==0.9.1
2-
autoenv==1.0.0
3-
bcrypt==3.1.7
4-
certifi==2019.9.11
5-
cffi==1.13.2
6-
Click==7.0
7-
coverage==4.5.4
8-
Flask==1.1.1
9-
Flask-API==1.1
10-
Flask-Bcrypt==0.7.1
11-
Flask-Migrate==2.5.2
12-
Flask-Script==2.0.6
13-
Flask-SQLAlchemy==2.4.1
14-
itsdangerous==1.1.0
15-
Jinja2==2.10.3
16-
Mako==1.0.6
17-
Markdown==3.1.1
18-
MarkupSafe==1.0
19-
psycopg2==2.8.4
20-
pycparser==2.17
21-
PyJWT==1.7.1
22-
python-coveralls==2.9.3
23-
python-editor==1.0.3
24-
PyYAML==5.1.2
25-
requests==2.22.0
26-
six==1.13.0
27-
SQLAlchemy==1.3.11
28-
Werkzeug==0.16.0
29-
1+
alembic~=1.7.5
2+
autoenv~=1.0.0
3+
autopep8~=1.6.0
4+
bcrypt~=3.2.0
5+
certifi~=2021.10.8
6+
cffi~=1.15.0
7+
charset-normalizer~=2.0.10
8+
click~=7.1.2
9+
coverage~=6.2
10+
Flask~=1.1.2
11+
Flask-API~=1.1
12+
Flask-Bcrypt~=0.7.1
13+
Flask-Migrate~=3.1.0
14+
Flask-Script~=2.0.6
15+
Flask-SQLAlchemy~=2.5.1
16+
greenlet~=1.1.2
17+
idna~=3.3
18+
importlib-metadata~=4.10.1
19+
importlib-resources~=5.4.0
20+
itsdangerous~=1.1.0
21+
Jinja2~=2.11.3
22+
Mako~=1.1.6
23+
Markdown~=3.3.6
24+
MarkupSafe~=2.0.1
25+
psycopg2~=2.9.3
26+
pycodestyle~=2.8.0
27+
pycparser~=2.21
28+
PyJWT~=2.3.0
29+
python-coveralls~=2.9.3
30+
python-dotenv~=0.19.2
31+
python-editor~=1.0.4
32+
PyYAML~=6.0
33+
requests~=2.27.1
34+
six~=1.16.0
35+
SQLAlchemy~=1.4.31
36+
toml~=0.10.2
37+
urllib3~=1.26.8
38+
Werkzeug~=1.0.1
39+
zipp~=3.7.0
Binary file not shown.

0 commit comments

Comments
 (0)