Boilerplate code for quick implimentation of REST API with JWT Authentication.
Report Bug
To get a local copy up and running follow these simple steps.
This is an example of how to list things you need to use the software and how to install them.
-
Python - I am using Anaconda distribution for easy installation of Python and pip
-
Click here to Install Anaconda
OR
-
You can download python from https://www.python.org/downloads/ and install
- Clone the repo
git clone https://github.com/reddimohan/flask-rest-api-barebones-with-authentication.git
- Create python environment so that we dont disturb other project versions
conda create --name rest_37 python=3.7
- Activate the
rest_37
environment
conda activate rest_37
- Install required python libs
pip install -r requirements.txt
- Install Mongodb in local machine OR You can create the database in the MongoCloud for free, click here to get free account
Note: If you have installed MongoDB locally you can follow 6th step otherwise ignore
- Setup password for mongo
- Go to mongo console by using
mongo
- Execute below queries
use library db.createUser( { user: "username", pwd: "password", roles: [ { role: "readWrite", db: "library" } ] } )
- Enable authentication in
/etc/mongodb.conf
- Restart mongodb service
- To connect to mongodb from console,
use mongo library -u admin -p
and then enter password when prompted
- Go to mongo console by using
- Configure database.yml by following steps
- rename
main/database.yml_sample
tomain/database.yml
- update DB_NAME, MONGO_USER, MONGO_PASS, HOST (You should have aquired this information from 5th or 6th step)
- rename
export FLASK_ENV=development
in Linux and use set in windows- execute
flask run
to run the application - Start the application
# python app.p
gunicorn app:app
# To see the no. of connections opened in MongoDB useful command
db.serverStatus().connections
- Clone the project
- copy .env_template to .env file and update all your configuration in the route directory
- Build the docker images using below command
docker-compose build
- Bring up the API server
docker-compose up -d # To run the service in Detach mode
OR
docker-compose up # to see the logs
- If everything works you can access the API docs on ```http://0.0.0.0:91/docs
# connect to to interactive terminal <mongodb> is the container name
docker exec -it mongodb bash
- You can login to mogodb CLI using below command
mongo -u username -p
You can find the crdentials from the .env file which you have created.
See the open issues for a list of proposed features (and known issues).
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE
for more information.
Project Link: https://github.com/reddimohan/flask-rest-api-barebones-with-authentication