Skip to content
Elias Ponvert edited this page Mar 26, 2012 · 2 revisions

Resources

Resources are the primary API concept; all operations are represented as an action on a resource. Mesh provides a declarative approach to defining resources and their actions, using Python classes.

A Resource specifies both a schema (using Scheme) for its attributes and a set of requests for the actions it supports. Resources are versioned and can be easily evolved through class inheritance.

Example

from mesh.standard import *

class Example(Resource):
    name = 'example'
    version = 1

    class schema:
        id = Integer(nonnull=True)
        name = Text(required=True, min_length=1)

    class query:
        endpoint = (GET, 'example')
        schema = {
            'limit': Integer(minimum=0)
        }
        responses = {
            OK: {'id': Integer()}
        }
The resource schema and endpoints -- here, the `query` endpoint -- are specified as inner classes.

Extended functionality is managed with versions, and can be implemented using inheritance, so only new functionality need be specified:

class Example(Example):
    name = 'example'
    version = 2

    class query(Example.query):
        schema = {
             'offset': Integer(minimum=0),
             'limit': Integer(minimum=0),
        }
Clone this wiki locally