我正在尝试使用 spyne 构建 REST Web 服务。到目前为止,我已经能够使用 ComplexModel 来表示我的资源。一些非常基本的东西,像这样(从例子中借来的):
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()
为了运行,我使用 curl -v " http://example.com:8000/get_meta ",我得到了我所期望的。
但是,如果我想访问诸如http://example.com:8000/resourceA/get_meta之类的资源层次结构怎么办?
谢谢你的时间!