willingc

Untitled

Jul 14th, 2014
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. def run_get():
  2. url = 'https://api.github.com/users/runnable'
  3.  
  4. # this issues a GET to the url. replace "get" with "post", "head",
  5. # "put", "patch"... to make a request using a different method
  6. r = requests.get(url)
  7.  
  8. return json.dumps(r.json(), indent=4)
  9.  
  10. @app.route('/run_post')
  11. def run_post():
  12. url = 'http://httpbin.org/post'
  13. data = {'a': 10, 'b': [{'c': True, 'd': False}, None]}
  14. headers = {'Content-Type': 'application/json'}
  15.  
  16. r = requests.post(url, data=json.dumps(data), headers=headers)
  17.  
  18. return json.dumps(r.json(), indent=4)
Advertisement
Add Comment
Please, Sign In to add comment