Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple flask example.

REST API with Flask

See https://flask.readthedocs.org/en/0.1/quickstart/ for more.

import flask

app = flask.Flask(__name__)

@app.route('/')
def index():
    return "hello"

@app.route('/submit', methods=['POST', 'GET'])
def submit():
    return flask.request.values['param']

app.run(host='::', port=5000, threaded=True)

Test it with curl. Note that I use zsh, the trailing % means that there was no \n sent.

The root endpoint.

> curl http://localhost:5000/      
Hello%

The /submit endpoint, using the GET method and query parameters.

> curl 'http://localhost:5000/submit?param=bar' -X GET
bar%

The /submit endpoint, using the POST method and form values.

> curl http://localhost:5000/submit -X POST --form param=bar
bar%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.