An object RESTational model
Перейти к файлу
Chris Adams afb3830f2c dataobject: fixed broken import in docstring 2011-03-31 03:44:54 +08:00
doc Updates for v1.1.1, including changelog and copyrights. 2010-05-21 11:52:43 -07:00
examples Updates for v1.1.1, including changelog and copyrights. 2010-05-21 11:52:43 -07:00
remoteobjects dataobject: fixed broken import in docstring 2011-03-31 03:44:54 +08:00
tests Updates for v1.1.1, including changelog and copyrights. 2010-05-21 11:52:43 -07:00
.gitignore Start a .gitignore file 2009-08-31 16:00:30 -07:00
CHANGES.rst Assigning release date. 2010-07-08 09:54:01 -07:00
LICENSE Updates for v1.1.1, including changelog and copyrights. 2010-05-21 11:52:43 -07:00
MANIFEST.in Change to an exclusive strategy for manifest building 2009-09-28 16:32:59 -07:00
README.rst Update mini Twitter example in package docs 2009-08-24 14:34:22 -07:00
requirements.txt Pin versions of packaged requirements to known good versions (including httplib2 0.5.0 with python 2.6 and GAE support) 2009-08-20 12:27:05 -07:00
setup.py Updates for v1.1.1, including changelog and copyrights. 2010-05-21 11:52:43 -07:00
stdeb.cfg Add config file for stdeb 2009-09-17 13:42:27 -07:00

README.rst

remoteobjects are real subclassable Python objects on which you can build a
rich API library.

remoteobjects provides easy coding and transfer between Python objects and a
JSON REST API. You can define the resources in a RESTful API as `RemoteObject`
classes and their properties. These objects then support using the basic HTTP
verbs to request and submit data to the API.

remoteobjects have:

* programmable conversion between Python objects and your API's JSON resource
  format

* full and correct HTTP support through the `httplib2` library, including
  caching and authentication

* delayed evaluation of objects to avoid unnecessary requests


Example
=======

For example, you can build a simplified Twitter API library in the shell::

    >>> from remoteobjects import RemoteObject, fields, ListObject
    >>> class Tweeter(RemoteObject):
    ...     name        = fields.Field()
    ...     screen_name = fields.Field()
    ...     location    = fields.Field()
    ...
    >>> class Tweet(RemoteObject):
    ...     text    = fields.Field()
    ...     source  = fields.Field()
    ...     tweeter = fields.Object(Tweeter, api_name='user')
    ...
    >>> class Timeline(ListObject):
    ...     entries = fields.List(fields.Object(Tweet))
    ...
    >>> tweets = Timeline.get('http://twitter.com/statuses/public_timeline.json')
    >>> [t.tweeter.screen_name for t in tweets.entries[0:3]]
    ['eddeaux', 'CurtisLilly', '8email8']


For web APIs
============

`remoteobjects` is your Object RESTational Model for web APIs. You can define
each type of resource as a `RemoteObject` subclass, with all the resource's
member data specified as `remoteobjects.field.Field` instances for lightweight
typing.

As provided, `remoteobjects` works with JSON REST APIs. Such an API should be
arranged as a series of resources available at URLs as JSON entities
(generally objects). The API server should support editing through ``POST``
and ``PUT`` requests, and return appropriate HTTP status codes for errors.

The remoteobjects module is not *limited* to a particular kind of API. The
`RemoteObject` interface is provided in `DataObject`, `HttpObject`, and
`PromiseObject` layers you can reuse, extend, and override to tailor objects
to your target API.


Dictionaries with methods
=========================

While you can use an HTTP module and plain JSON coding to convert API
resources into dictionaries, `remoteobjects` gives you real objects with
encapsulated behavior instead of processing with external functions. A
`RemoteObject` instance's behavior is clearly packaged in your `RemoteObject`
subclass, where it is not only enforced through use of the object interface
but extensible and replaceable through plain old subclassing.