|
1 | 1 | # flask-rest-api [](https://travis-ci.org/gitgik/flask-rest-api) |
2 | | -A flask-driven restful API for Bucketlist interactions |
3 | 2 |
|
| 3 | +A flask-driven restful API for Bucketlist interactions |
4 | 4 |
|
5 | 5 | ## Technologies used |
| 6 | + |
6 | 7 | * **[Python3](https://www.python.org/downloads/)** - A programming language that lets you work more quickly (The universe loves speed!). |
7 | 8 | * **[Flask](flask.pocoo.org/)** - A microframework for Python based on Werkzeug, Jinja 2 and good intentions |
8 | 9 | * **[Virtualenv](https://virtualenv.pypa.io/en/stable/)** - A tool to create isolated virtual environments |
9 | 10 | * **[PostgreSQL](https://www.postgresql.org/download/)** – Postgres database offers many [advantages](https://www.postgresql.org/about/advantages/) over others. |
10 | 11 | * Minor dependencies can be found in the requirements.txt file on the root folder. |
11 | 12 |
|
12 | | - |
13 | 13 | ## Installation / Usage |
| 14 | + |
14 | 15 | * 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). |
15 | 16 | * After this, ensure you have installed virtualenv globally as well. If not, run this: |
| 17 | + |
| 18 | + ```bash |
| 19 | + pip install virtualenv |
16 | 20 | ``` |
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 |
22 | 26 | ``` |
23 | 27 |
|
| 28 | +* ### Dependencies |
24 | 29 |
|
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: |
30 | 31 |
|
31 | | - 2. Create and fire up your virtual environment in python3: |
| 32 | + ```bash |
| 33 | + cd flask-rest-api |
32 | 34 | ``` |
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 |
35 | 41 | ``` |
36 | 42 |
|
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 |
44 | 49 | ``` |
45 | 50 |
|
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: |
48 | 52 |
|
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" |
50 | 57 | ``` |
| 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 |
51 | 64 | (venv)$ pip install -r requirements.txt |
52 | 65 | ``` |
53 | 66 |
|
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 |
57 | 73 | > CREATE DATABASE flask_api; |
58 | 74 | ``` |
59 | | - Then, make and apply your Migrations |
60 | | - ``` |
61 | | - (venv)$ python manage.py db init |
62 | 75 |
|
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 |
65 | 80 |
|
66 | | - And finally, migrate your migrations to persist on the DB |
| 81 | + (venv)$ flask db migrate |
67 | 82 | ``` |
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 |
69 | 88 | ``` |
70 | 89 |
|
71 | | -* #### Running It |
| 90 | +* ### Running the Server |
| 91 | + |
72 | 92 | On your terminal, run the server using this one simple command: |
73 | | - ``` |
| 93 | + |
| 94 | + ```bash |
74 | 95 | (venv)$ flask run |
75 | 96 | ``` |
| 97 | + |
76 | 98 | You can now access the app on your local browser by using |
77 | | - ``` |
| 99 | + |
| 100 | + ```bash |
78 | 101 | http://localhost:5000/bucketlists/ |
79 | 102 | ``` |
| 103 | + |
80 | 104 | Or test creating bucketlists using Postman |
0 commit comments