我正在使用Cornice和金字塔来构建一个API。大多数操作都是REST操作,所以它非常适合。但对于他们中的一些人,我不想遵循REST原则。
例如,在这个类中使用cornice :我们如何在: /gianluca/element/{id}/action下公开一个操作。
我知道我可以有另一个路径为: /gianluca/element/{id}/action的类,带有get或post函数。但我只是想以一种干净的方式使用这个函数。
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发布于 2019-02-05 22:37:24
为此,您应该使用cornice.Service应用编程接口。cornice.resource是用于纯REST的。
https://stackoverflow.com/questions/53063596
复制相似问题