Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Simple flask example.

REST API with Flask

See for more.

import flask

app = flask.Flask(__name__)

def index():
    return "hello"

@app.route('/submit', methods=['POST', 'GET'])
def submit():
    return flask.request.values['param']'::', 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/      

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

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

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

> curl http://localhost:5000/submit -X POST --form param=bar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment