Flask-RestGlue integrates Flask, MongoDB, OpenAPI in a simple and elegant way
Project description
Flask-RestGlue(ALPHA)
Integrates Flask + MongoDB + OpenAPI in a simple and elegant way!
Explore the docs »
View Demo
·
Report Bug
·
Request Feature
Contents
Table of Contents
Example
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:
Expected output:
curl -v -d '{"email":"a@b.com","password":"xyz"}' \
-H "Content-Type: application/json" http://localhost:5000/user
#< HTTP/1.0 200 OK
#< Content-Type: application/json
#< Content-Length: 45
#<
#{
# "_id": "a@b.com",
# "password": "xyz"
#}
curl -v http://localhost:5000/users
#< HTTP/1.0 200 OK
#< Content-Type: application/json
#< Content-Length: 57
#<
#[
# {
# "_id": "a@b.com",
# "password": "xyz"
# }
#]
curl -v http://localhost:5000/user/a@b.com
#< HTTP/1.0 200 OK
#< Content-Type: application/json
#< Content-Length: 45
#<
#{
# "_id": "a@b.com",
# "password": "xyz"
#}
curl -v -X PUT -d '{"password":"new_pass"}' \
-H "Content-Type: application/json" http://localhost:5000/user/a@b.com
#< HTTP/1.0 200 OK
#< Content-Type: application/json
#< Content-Length: 50
#<
#{
# "_id": "a@b.com",
# "password": "new_pass"
#}
curl -v -X DELETE http://localhost:5000/user/a@b.com
#< HTTP/1.0 200 OK
#< Content-Type: application/json
#< Content-Length: 45
#<
#{
# "_id": "a@b.com",
# "password": "xyz"
#}
Quick Start
Requires docker and python 3.9
1 - install local MongoDB
mkdir -p ~/mongodata
docker run -d --rm -p 27017:27017 -v ~/mongodata:/data/db --name mongodb mongo
2 - Install this library
pip install Flask-RestGlue
3 - Pull the code
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
4 - Run the code
python tut01_hello_world.py
In another terminal window
bash tut01_hello_world.sh
References :notebook:
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Flask-RestGlue-0.0.1.tar.gz
(11.4 kB
view hashes)
Built Distribution
Close
Hashes for Flask_RestGlue-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 728dca5aa11988777e5f6f345c593e26aa4ece09137da45ad368ba50ee5cda02 |
|
MD5 | 926b7584ef98d568742a79572821c0c9 |
|
BLAKE2b-256 | 03af86b707d5fe2ba9948b08a0359f841e4a201309c44963c589b118a358fedf |