Skip to content

REST API using python and flask. Data stored in mongodb

Notifications You must be signed in to change notification settings

abh-swar/python-flask-mongodb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

python-flask-mongodb

REST API using python and flask. Data stored in mongodb

Create a virtual environment and use it

mkvirtualenv python-flask-mongodb
workon python-flask-mongodb

Install the dependencies using pip

pip3 install -r requirements.txt

Install MongoDb and start its daemon

mongod

Login into the mongo shell and create a database named python_flask_mongodb

mongo
use python_flask_mongodb

Run the app

python3 application.py

Browse the app in

http://127.0.0.1:5000/

Create single user using curl

curl -XPOST http://localhost:5000/api/v1/user -H "Content-Type: application/json" -d '{
    "name": "Abhinayak Swar",
    "location": "Nepal"
}'

Create multiple user using curl

curl -XPOST http://localhost:5000/api/v1/user -H "Content-Type: application/json" -d '[
    {
        "name": "Atul Pradhan",
        "location": "Nepal"
    },
    {
        "name": "Pramod Sthapit",
        "location": "Nepal"
    }
]'

Get all the users

curl -XGET http://localhost:5000/api/v1/user

Edit user by id

curl -XPUT http://localhost:5000/api/v1/user/{user_id} -H "Content-Type: application/json" -d '{
    "name": "Abhinayak Swar 123",
    "location": "Nepal"
}'

Delete user by id

curl -XDELETE http://localhost:5000/api/v1/user/{user_id}

About

REST API using python and flask. Data stored in mongodb

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages