The surf.rest Module

class surf.rest.Rest(resources_namespace, concept_class)[source]

Bases: object

The Rest class handles the generation of REST like methods to perform CRUD operations on a surf.resource.Resource instance

note: The REST api exposed is designed in accordance with the REST controller used in pylons applications, it adheres to the REST specification and offers extra features

Parameters:
  • resources_namespace (rdflib.namespace.Namespace or str) – the uri used by instances
  • concept_class (surf.resource.Resource) – the class for which the REST interface is exposed
create(json_params)[source]

REST : POST /: Create a new item, creates a new surf.resource.Resource instance

Parameters:json_params (dict) – extra JSON parameters to set as instance attributes
delete(id)[source]

REST : DELETE /id: Delete an existing item. removes an instance from the underlying surf.store.Store store

Parameters:id (str) – the resources id
edit(id, json_params)[source]

REST : GET /id;edit: alias for surf.rest.Rest.update() method

Parameters:
  • id (str) – the resources id
  • json_params (dict) – extra JSON parameters to set as instance attributes
index()[source]

REST : GET /: All items in the collection,

Returns:all instances for the current surf.resources.Resource
Return type:list or surf.resources.ResultProxy
new(json_params)[source]

REST : GET /new: Form to create a new item. alias for surf.rest.Rest.create() method

Parameters:json_params (dict) – extra JSON parameters to set as instance attributes
classmethod resource(session, resources_namespace, concept_class, id)[source]

convenience method to get a resource given the arguments

Parameters:
  • session (surf.session.Session) – the SuRF session
  • resources_namespace (rdflib.namespace.Namespace or str) – the uri used by instances
  • concept_class (surf.resource.Resource) – the class for which the REST interface is exposed
  • id (str) – the resources id
Returns:

the resource

Return type:

surf.resources.Resource

show(id)[source]

REST : GET /id: Show a specific item. show / retrieve the specified resource

Parameters:id (str) – the resources id
Returns:the resource
Return type:surf.resources.Resource
update(id, json_params)[source]

REST : PUT /id: Update an existing item., update an instances attributes with the supplied parameters

Parameters:
  • id (str) – the resources id
  • json_params (dict) – extra JSON parameters to set as instance attributes