使用金字塔构建Web服务

时间:2015-02-04 10:24:27

标签: python web-services pyramid

我是一名初学者,正在尝试学习如何使用Pyramid Web框架构建RESTful Web服务。我熟悉Web服务的基础知识,并且我有使用Java构建它们的经验。我打算不使用像Cornice这样的网络服务构建者。 我必须在路线配置中添加任何具体内容吗? 有人可以告诉我从哪里开始或提供任何有用的链接来学习使用Pyramid构建Web服务?

1 个答案:

答案 0 :(得分:4)

@view_defaults(route_name='myservice')
class MyServiceView(object):

    def __init__(self, request):
        self.request = request

    @view_config(request_method='GET')
    def get(self):
        return Response(u'This is the GET view')

    @view_config(request_method='POST')
    def post(self):
        return Response(u'This is the POST view')

    @view_config(request_method='PUT')
    def put(self):
        return Response(u'This is the PUT view')

    @view_config(request_method='DELETE')
    def delete(self):
        return Response(u'This is the DELETE view')