-
Notifications
You must be signed in to change notification settings - Fork 2
Resources
Elias Ponvert edited this page Mar 26, 2012
·
2 revisions
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.
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()}
}
`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),
}