HTTP Clients

HTTP Clients are object based on restclient.http.HTTPClient that perform HTPP operations.

You can choose the one you want as httpclient in Resource or RestClient:

from restclient.http import CurlHTTPClient
httpclient = CurlHTTPClient()
res = Resource(httpclient=httpclient)

Functions

restclient.http.createHTTPClient()
Create default HTTP client instance prefers Curl to urllib
restclient.http.getDefaultHTTPClient()

Return the default http client instance instance if no client has been set, it will create a default client.

Returns:the default client
restclient.http.setDefaultHTTPClient(httpclient)
set default httpClient :param http: RestClient

Clients:

class restclient.http.HTTPClient

Interface for HTTP clients

request(url, method='GET', body=None, headers=None)

Perform HTTP call and manage , support GET, HEAD, POST, PUT and DELETE

Parameters:
  • url – url on which to perform the actuib
  • body – str
  • headers – dict, optionnal headers that will be added to HTTP request
Returns:

object representing HTTP Response

class restclient.http.Urllib2HTTPClient(*handlers)

HTTP Client that use urllib2. This module is included in python so i mean that you don’t need any dependancy to run this client and restclient.

urllib2 is very powerfull and you can use many handlers to manage authentification and proxies.

See also

Urllib2

__init__(*handlers)

Constructor for Urllib2HTTPClien

Parameters:
  • *handlers

    add here any urllib2 handlers.

For example here is a way to have your urllib2 based client using http basic authentification :

password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
password_mgr.add_password(None, "%s/%s" % (self.url, "auth"),
    "test", "test")
auth_handler = urllib2.HTTPBasicAuthHandler(password_mgr)

httpclient = Urllib2HTTPClient(auth_handler)
class restclient.http.CurlHTTPClient(timeout=None)

An HTTPClient that uses pycurl.

Pycurl is recommanded when you want fast access to http resources. We have added some basic management of authentification and proxies, but in case you want something specific you should use urllib2 or httplib2 http clients. Any patch is welcome though ;)

Here is an example to use authentification with curl httpclient :

httpclient = CurlHTTPClient()
httpclient.add_credentials("test", "test")        

See also

Pycurl

class restclient.http.HTTPLib2HTTPClient(http=None, cache=None)

An http client that uses httplib2 for performing HTTP requests. This implementation supports HTTP caching.

See also

Httplib2

Table Of Contents

Previous topic

Resource

This Page

Quick search