Created
June 11, 2016 18:20
-
-
Save omarayad1/155268e8e3ffca32ddddbc6c4474195b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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