Source

py-restclient / docs / resource.txt

The default branch has multiple heads

.. _resource_ref:

Resource
========

.. module:: restclient

This module provide a common interface for all HTTP requests. This
module make HTTP requests using `Pycurl`_ by default if installed or
`Httplib2`_.

Example: 

    >>> from restclient import Resource
    >>> res = Resource('http://friendpaste.com')
    >>> res.get('/5rOqE9XTz7lccLgZoQS4IP',headers={'Accept': 'application/json'})
    u'{"snippet": "hi!", "title": "", "id": "5rOqE9XTz7lccLgZoQS4IP", "language": "text", "revision": "386233396230"}'
    >>> res.get('/5rOqE9XTz7lccLgZoQS4IP',headers={'Accept': 'application/json'}).http_code
    200
    
Data returned are unicode or binaries.

Resource class
--------------

.. autoclass:: restclient.rest.Resource

    **Properties**

    .. attribute:: uri

        Str, full uri to the server.

    .. attribute:: transport

        Any instance of object based on 
        `restclient.transport.HTTPTransportBase`. By default it will use 
        a client based on `pycurl <http://pycurl.sourceforge.net/>`_ if 
        installed or `restclient.http.HTTPLib2Transport`,a transport based on 
        `Httplib2 <http://code.google.com/p/httplib2/>`_ or make your
        own depending of the option you need to access to the serve
        (authentification, proxy, ....).


    **Methods**

    .. automethod:: restclient.rest.Resource.clone

    .. automethod:: restclient.rest.Resource.__call__

    .. automethod:: restclient.rest.Resource.get

    .. automethod:: restclient.rest.Resource.head

    .. automethod:: restclient.rest.Resource.delete

    .. automethod:: restclient.rest.Resource.post

    .. automethod:: restclient.rest.Resource.put
    
    .. automethod:: restclient.rest.Resource.request

    .. automethod:: restclient.rest.Resource.update_uri

RestClient class
----------------

RestClient represent a simple HTTP client. **New in 1.1** By default all urls are utf8
encoded. But you could change default charset, safe characters and
decide that keys don't need to be encoded.

.. autoclass:: restclient.rest.RestClient

    

    **Properties**

    .. attribute:: transport

        Any http instance of object based on 
        `restclient.http.HTTPTransportBase`. By default it will use 
        a client based on `pycurl <http://pycurl.sourceforge.net/>`_ if 
        installed or `restclient.http.HTTPLib2Transport`,a transport based on 
        `Httplib2 <http://code.google.com/p/httplib2/>`_ or make your
        own depending of the option you need to access to the serve
        (authentification, proxy, ....).

    .. describe:: charset
        
        By default it's 'utf-8', it define charset of urls.

    .. describe:: encode_keys

        By default True. Encode params keys

    .. describe:: safe

        By default is ":/", define which charaters are safe in url and
        don't need to be encoded.


    **Methods**

    .. automethod:: restclient.rest.RestClient.get

    .. automethod:: restclient.rest.RestClient.head

    .. automethod:: restclient.rest.RestClient.delete

    .. automethod:: restclient.rest.RestClient.post

    .. automethod:: restclient.rest.RestClient.put

    .. automethod:: restclient.rest.RestClient.request

.. _Pycurl: http://pycurl.sourceforge.net/
.. _Httplib2: http://code.google.com/p/httplib2/