Flask-request-params provides Rails-like interface to HTTP Request Parameters for Flask.
Project description
Flask-request-params provides Rails-like interface to HTTP Request Parameters for Flask.
Supports mixed parameters(GET, POST, POST-JSON), Rails Strong_Parameters.
Installation
To install Flask-request-params, simply:
pip install flask-request-params
Or alternatively, you can download the repository and install manually by doing:
git clone git@github.com:bluele/flask-request-params.git cd flask-request-params python setup.py install
Examples
See examples for more code.
Server code
from flask import Flask, request, render_template, jsonify from flask_request_params import bind_request_params app = Flask(__name__) app.secret_key = 'secret' # bind rails like params to request.params app.before_request(bind_request_params) # just return request.params @app.route('/echo/<path>', methods=['GET', 'POST']) def echo(path): return jsonify(request.params) # support strong_parameters @app.route('/user', methods=['POST']) def create_user(): user = request.params.require('user').permit('name', 'password') # do something return jsonify(user) # serve at localhost:5000 app.run(debug=True)
Client code
# support hash type $ curl -X POST http://localhost:5000/echo/user -d 'user[name]=john&user[password]=pass' { "path": "user", "user": { "name": "john", "password": "pass" } } # support array type $ curl -X POST http://localhost:5000/echo/lang -d 'languages[]=python&languages[]=golang' { "path": "lang", "languages": [ "python", "golang" ] } # support strong_parameters $ curl -X POST http://localhost:5000/user -d 'user[name]=bluele&user[password]=password' { "name": "bluele", "password": "password" }
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
Close
Hashes for Flask-request-params-0.2.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | e1f27b6e974e2fdd2baecbb66cc72690cd01d9fc5b7a41e07dd65154c045da1f |
|
MD5 | 5fbcaad71ae63eb3280318f7a3182c07 |
|
BLAKE2b-256 | cc3d5f9ec64cbc990dbc9ac5072da6e9e3df7953ecd3d0924fc7541bf5b8eb83 |