🚀 Integrates Flask + MongoDB(mongoengine) + OpenAPI in a simple and elegant way!
MIT License
For a fullstack boilerplate, visit https://github.com/abassel/Flask_RestGlue_Svelte_Docker
import mongoengine as mongo
from flask_rest_glue import FlaskRestGlue
mongo.connect("pyglue", host='localhost:27017')
api = FlaskRestGlue()
@api.rest_model()
class User(mongo.Document):
# id = mongo.StringField(primary_key=True)
email = mongo.StringField(primary_key=True)
password = mongo.StringField()
api.run()
Go to http://127.0.0.1:5000/spec_doc or http://127.0.0.1:5000/spec_rdoc to see the documentation bellow:
curl -v -d '{"email":"[email protected]","password":"xyz"}' \
-H "Content-Type: application/json" http://localhost:5000/user
#< HTTP/1.0 200 OK
#< Content-Type: application/json
#< Content-Length: 45
#<
#{
# "_id": "[email protected]",
# "password": "xyz"
#}
curl -v http://localhost:5000/users
#< HTTP/1.0 200 OK
#< Content-Type: application/json
#< Content-Length: 57
#<
#[
# {
# "_id": "[email protected]",
# "password": "xyz"
# }
#]
curl -v http://localhost:5000/user/[email protected]
#< HTTP/1.0 200 OK
#< Content-Type: application/json
#< Content-Length: 45
#<
#{
# "_id": "[email protected]",
# "password": "xyz"
#}
curl -v -X PUT -d '{"password":"new_pass"}' \
-H "Content-Type: application/json" http://localhost:5000/user/[email protected]
#< HTTP/1.0 200 OK
#< Content-Type: application/json
#< Content-Length: 50
#<
#{
# "_id": "[email protected]",
# "password": "new_pass"
#}
curl -v -X DELETE http://localhost:5000/user/[email protected]
#< HTTP/1.0 200 OK
#< Content-Type: application/json
#< Content-Length: 45
#<
#{
# "_id": "[email protected]",
# "password": "xyz"
#}
Requires docker and python 3.9
mkdir -p ~/mongodata
docker run -d --rm -p 27017:27017 -v ~/mongodata:/data/db --name mongodb mongo
pip install Flask-RestGlue
curl -s -O -L https://github.com/abassel/Flask-RestGlue/blob/master/example/tut01_hello_world.py
curl -s -O -L https://github.com/abassel/Flask-RestGlue/blob/master/example/tut01_hello_world.sh
python tut01_hello_world.py
In another terminal window
bash tut01_hello_world.sh