我正在嘗試使用spyne構建REST Web服務。到目前爲止,我已經能夠使用ComplexModel來表示我的資源。一些非常基本的,像這樣(從例子中借來的):如何使用spyne構建REST層次結構
class Meta(ComplexModel):
version = Unicode
description = Unicode
class ExampleService(ServiceBase):
@srpc(_returns=Meta)
def get_meta():
m = Meta()
m.version="2.0"
m.description="Meta complex class example"
return m
application = Application([ExampleService],
tns='sur.factory.webservices',
in_protocol=HttpRpc(validator='soft'),
out_protocol=JsonDocument()
)
if __name__ == '__main__':
wsgi_app = WsgiApplication(application)
server = make_server('0.0.0.0', 8000, wsgi_app)
server.serve_forever()
要運行我用捲曲-v「http://example.com:8000/get_meta」和我得到了我的期望。
但是如果我想訪問一些像http://example.com:8000/resourceA/get_meta這樣的資源層次呢?
謝謝你的時間!
我將如何去訪問集合?我需要//並將其與來自類的方法匹配,並且能夠接收resource_id並從那裏開始工作......但如何使用裝飾器來完成它? –
Javier
明白了,不是佔位符,它是一個變量!大! –
Javier