Skip to content

jar-o/flask-bson

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flask-BSON

Let your Flask endpoints speak application/bson.

A Flask extension that gives you utilities to allow your Flask endpoints to process and respond in the BSON format.

Installation

You can install the extension with pip like

pip install flask-bson

Usage

The extension relies on two pieces of functionality basically. The accept_bson view decorator which parses requests into a usable requests.bson_data dictionary, and bsonify which works a lot like the much-loved jsonify -- it turns a dictionary into a valid BSON response.

Here's a full sample implementation:

from flask import Flask, request
from flask_bson import accept_bson, bsonify

app = Flask(__name__)

@app.route('/', methods=['POST'])
@accept_bson(require_bson = True)
def echobson():
    return bsonify(request.bson_data)

if __name__ == '__main__':
    app.run(debug=True)

See demo/run.sh for an example of how to use curl to send a BSON request.

About

Let your Flask endpoints speak application/bson

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published