Search code examples
pythonweb-servicespyramid

Building a web service with Pyramid


I am a beginner trying to learn how to build a RESTful web service with Pyramid web framework. I am familiar with the basics of Web services and I have experience building them in Java. I plan on not using web service builders like Cornice. Is there anything specific I have to add in the route configurations? Can someone please tell me where to start or give any useful links for learning to build web services with Pyramid?


Solution

  • @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')