HTTP Transports

HTTP Transports are object based on restclient.transport.HTTPTransportBase that perform HTPP operations.

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

from restclient.transport import CurlTransport
transport = CurlTransport()
res = Resource(transport=transport)

Functions

restclient.transport.createHTTPTransport()
Create default HTTP client instance prefers Curl to urllib
restclient.transport.getDefaultHTTPTransport()

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

Returns:the default client
restclient.transport.setDefaultHTTPTransport(httptransport)
set default http transport :param http: RestClient

Response

class restclient.transport.HTTPResponse(info)

An object more like email.Message than httplib.HTTPResponse.

>>> from restclient import Resource
>>> res = Resource('http://e-engura.org')
>>> from restclient import Resource
>>> res = Resource('http://e-engura.org')
>>> page = res.get()
>>> res.status
200
>>> res.response['content-type']
'text/html'
>>> logo = res.get('/images/logo.gif')
>>> res.response['content-type']
'image/gif'

Transports:

class restclient.transport.HTTPTransportBase(proxy_infos=None)

Interface for HTTP clients

__init__(proxy_infos=None)

constructor for HTTP transport interface

Parameters:
  • proxy_infos – dict, infos to connect via proxy:
{
    'proxy_user': 'XXXXXXX',
    'proxy_password': 'XXXXXXX',
    'proxy_host': 'proxy',
    'proxy_port': 8080,
}
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

add_credentials(user, password)
class restclient.transport.CurlTransport(timeout=None, proxy_infos=None)

An HTTP transportthat 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 = CurlTransport()
httpclient.add_credentials("test", "test")        

See also

Pycurl

__init__(timeout=None, proxy_infos=None)

Curl transport constructor

Parameters:
  • timeout – int, timeout of request
  • proxy_infos – dict, infos to connect via proxy:
{
    'proxy_user': 'XXXXXXX',
    'proxy_password': 'XXXXXXX',
    'proxy_host': 'proxy',
    'proxy_port': 8080,
}
add_credentials(user, password)
class restclient.transport.HTTPLib2Transport(proxy_infos=None, http=None)

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

See also

Httplib2

__init__(proxy_infos=None, http=None)
Parameters:
  • proxy_infos – dict, infos to connect via proxy:
{
    'proxy_user': 'XXXXXXX',
    'proxy_password': 'XXXXXXX',
    'proxy_host': 'proxy',
    'proxy_port': 8080,
}
Parameters:
  • http – An httplib2.HTTP instance.
add_credentials(user, password)