Giter Club home page Giter Club logo

flask-request-params's Introduction

Flask-request-params

https://travis-ci.org/bluele/Flask-request-params.svg?branch=master

Flask-request-params provides Rails-like interface to HTTP Request Parameters for Flask.

Supports mixed parameters(GET, POST, POST-JSON), Rails Strong_Parameters.

Documents are here.

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 [email protected]:bluele/flask-request-params.git
cd flask-request-params
python setup.py install

Examples

See examples for more code.

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"
}

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)

@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)

flask-request-params's People

Contributors

bluele avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.