Skip to content

Instantly share code, notes, and snippets.

@omarayad1
Created June 11, 2016 18:20
Show Gist options
  • Save omarayad1/155268e8e3ffca32ddddbc6c4474195b to your computer and use it in GitHub Desktop.
Save omarayad1/155268e8e3ffca32ddddbc6c4474195b to your computer and use it in GitHub Desktop.
from requests import get,post
from json import loads
PORT = "5000"
HOST = "localhost"
get_request_content = get('http://'+HOST+':'+PORT+'/hello').content
print "response data: ", loads(get_request_content)['content']
post_request_content = post('http://'+HOST+':'+PORT+'/incr', data={"num":548}).content
print "response data: ", loads(post_request_content)['content']
from flask import Flask, jsonify, request
app = Flask(__name__)
# sample get request
@app.route("/hello", methods=['GET'])
def hello():
return jsonify({"content": "Hello World!"})
# sample post request
@app.route("/incr", methods=['POST'])
def incr():
return jsonify({"content": int(request.values["num"])+1})
if __name__ == "__main__":
app.run(host='0.0.0.0', port=5000) # change the port to your liking
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment