Module rhino.resource

Classes

class Resource

Represents a REST resource.

This class can be used in multiple ways:

As a standalone resource, using it's methods to register handlers:

my_resource = Resource()

@my_resource.get
def get_resource(request):
    # ...

As a class decorator for class-based resources:

@Resource
class MyResource(object):
    @get
    def index(self, request):
        # ...

As a wrapper to create resouces from custom objects:

class MyClass(object):
    def __init_(self, *args):
        # ...

    @get
    def index(self, request):
        # ...

my_resource = Resource(MyClass())

When used as a wrapper or class decorator, handlers will be picked up from methods of the wrapped instance or class that have been decorated with one of the decorator functions provided by this module (get, post, etc.)

Additionally, if the wrapped object implements from_url, that method will be called before any handler to filter the URL parameters that will be passed to the handler as keyword arguments.

When used as a standalone instance, functions can be registered as handlers using the instance's methods, as shown above. The from_url method can be used in the same way to register a filter for URL parameters.

__init__(wrapped=None)

delete(*args, **kw)

Install the decorated function as a handler for DELETE requests.

from_url(fn)

Install the decorated function as a filter for URL parameters.

get(*args, **kw)

Install the decorated function as a handler for GET requests.

options(*args, **kw)

Install the decorated function as a handler for OPTIONS requests.

patch(*args, **kw)

Install the decorated function as a handler for PATCH requests.

post(*args, **kw)

Install the decorated function as a handler for POST requests.

put(*args, **kw)

Install the decorated function as a handler for PUT requests.

Functions

make_response(obj)

Try to coerce an object into a Response instance.

get(*args, **kw)

Mark the decorated function as a handler for GET requests.

post(*args, **kw)

Mark the decorated function as a handler for POST requests.

put(*args, **kw)

Mark the decorated function as a handler for PUT requests.

delete(*args, **kw)

Mark the decorated function as a handler for DELETE requests.

patch(*args, **kw)

Mark the decorated function as a handler for PATCH requests.

options(*args, **kw)

Mark the decorated function as a handler for OPTIONS requests.