Resources¶
-
class
repose.resources.
Resource
(**kwargs)¶ Representation of an API resource
-
parent_resource
¶ list
A list of all parent resources to this one. Often useful in generating endpoints for child resources. Parent resources are stored as
weakref.ref()
-
api
¶ Api
The API instance
-
class
Meta
¶ Override this class in child resources to provide configuration details.
The endpoints listed here can include placeholders in the form
{fieldname}
. If this resource is a child of another resource, the parent resource’s fields may be accessed in the form{parentname_fieldname}}
, whereparentname
is the lowercase class name.For example, a
User
resource may contain severalComment
resources. In which case theendpoint
for theComment
could be:/user/{user_id}/comments/{id}
You could also expand the latter placeholder as follows:
/user/{user_id}/comments/{comment_id}
-
Resource.
__init__
(**kwargs)¶ Initialise the resource with field values specified in
*kwargs
Parameters: **kwargs – Fields and their (decoded) values
-
classmethod
Resource.
contribute_api
(api)¶ Contribute the API backend to this resource and its managers.
Note
Mainly for internal use
-
Resource.
contribute_parents
(parent=None)¶ Furnish this class with it’s parent resources
Note
Mainly for internal use
-
Resource.
prepare_save
(encoded)¶ Prepare the resource to be saved
Will only return values which have changed
Can be used as a hook with which to tweak data before sending back to the server. For example:
def prepare_save(encoded): prepared = super(MyResource, self).prepare_save(encoded) prepared['extra_value'] = 'Something' return prepared
Parameters: encoded (dict) – The encoded resource data
-
Resource.
save
()¶ Persist pending changes
-