GET and POST Requests with the Naked Python Framework

GET and POST requests are performed with the HTTP class in the Naked.toolshed.network module.

For text:

from Naked.toolshed.network import HTTP

# GET request
http = HTTP("http://httpbin.org/status/200")
if http.get_status_ok():
    response_text = http.res.text

# POST request
http = HTTP("http://httpbin.org/post")
if http.post_status_ok():
    response_text = http.res.text

And for binary data:

from Naked.toolshed.network import HTTP

# GET request
http = HTTP("https://github.com/chrissimpkins/naked/tarball/master")
if http.get_status_ok():
    response_data = http.res.content

# POST request
http = HTTP("https://github.com/chrissimpkins/naked/tarball/master")
if http.post_status_ok():
    response_data = http.res.content
Advertisements