我用的檐口和金字塔建造的API。大多数操作是REST操作,因此非常适应。但他们中的一些,我不想遵循REST原则。
例如,在使用檐口这个类:我们怎样才能暴露下一个动作:/赞布罗塔/元/ {ID} /动作。
我知道我可以有另外的类路径:用GET或POST功能/赞布罗塔/元/ {ID} /动作。但我只是想在一个干净的方式有这个功能。
from cornice.resource import resource
from pyramid.security import Allow
from pyramid.security import Everyone
@resource(collection_path='/gianluca/element', path='/gianluca/element/{id}')
class MyElement(object):
def __init__(self, request, context=None):
self.request = request
def __acl__(self):
return [(Allow, Everyone, 'everything')]
def collection_get(self):
return {'collection': 'all collection'}
def get(self):
return "Element id : " + self.request.matchdict['id']
# TODO
def action(self):
# elementLib.launchElement()
# Just a standart web service not in rest but i would like to have it under :
# /gianluca/element/{id}/action
return True
对于这样的目的,你应该使用cornice.Service
API。该cornice.resource
是纯粹的REST。