Another boilerplate for flask-restful web service (Including flask-sqlalchemy, flask-jwt, Swagger, ...)
This project is going to be an opensource version of something like Delicious) to save and share your favorite bookmarks.
Now you can save your favourite bookmarks, categories them, return them by category or by looking for some special keyword in their URL, see your friends activities (If they are public), …
And last but not least, you can setup Restfulness
on your own workspace, because both server and clients are opensource and ready for use.
If you have docker
and docker-compose
installed, then simply you can run:
(Make sure you are in root directory of project which is the folder that contains api.py
)
docker-compose up
And that’s it :) now you can open http://localhost:5000/apidocs
to see available APIs.
(To run CI tests using pytest
in this way, you can simply run docker-compose run app python -m pytest
; But make sure to wait a few seconds for MySql to get ready)
By default, our docker-compose
configuration will disables root
‘s password for MySql
after initialization; So app connects to restfulness
database with test
user which is created using enviromental variables in docker-compose.yml
file. If you want to changes this setting, make
sure to read MySql Docker Documentation, then change docker-compose.yml
and config.json
correctly.
Note: By default, Database is persistent using Docker Volumes, so you don’t need to worry about losing your data unless you turn off everything using docker-compose down -v
command. To make a long story short and for more information, take a look
at this.
At the very beginning, you have to initiate a virtual environment with this:
sudo apt install -y python3-venv
python3 -m venv venv
And then every time that you want to run it:
source venv/bin/activate
python -m pip install -r requirements.txt
Then you can run
python api.py
This project supports both MySql
and SQLite
as its database.
By default, this code uses MySql
as its main database but if you want to use SQLite
(which is placed in tests/test.db
) for testing purposes, make sure to change mysql
option to false
in config.json
.
Else, if you want to continue using MySql
, please follow instructions below:
Before running api.py
, make sure you have mysql server
installed and change db connection inconfig.json
.
To install mysql server
in Debian based distributions you can run:
sudo apt install mysql-server
sudo mysql_secure_installation
Now change username
, password
and db
in config.json
to make the app able to connect
to database.
Before running the app, make sure to check all values in config.json
file.
Default values:
SMTP:
If you want to be able to enable sending Email part, you have to configure SMTP
part in config file.
(If you don’t have any service, you can use Google’s Free SMTP Server, but if you are using this, please make sure to Enable less secure apps to access Gmail).
Pagination:
Something that is untested is broken!
To run tests, make sure you are in root directory of the project (the directory that contains api.py
file) then run:
python -m pytest
To see available APIs, go to http://localhost:5000/apidocs
(We are using Flasgger for our API’s documentation)
/forget
endpoint, containing user's username
.User's ID, Valid 8 digit code and expire date
. (We use ItsDangerous for creating that hash, so it’s safe.)/verify
endpoint, containing user's entered 8 digit code
and hash that was obtained from previous call
./reset
endpoint, containing Reset password token that is obtained from previous call
and user's new password
.MIT
For more information read this: