10

I tried to use a def patch(): method in my webapp2.RequestHandler to support partial resource updates, but then saw that the allowed methods are frozen in webapp2.py:

allowed_methods = frozenset(('GET', 'POST', 'HEAD', 'OPTIONS', 'PUT',
                             'DELETE', 'TRACE'))

How can I extend webapp2.RequestHandler or modify the WSGIApplication class to allow the PATCH HTTP method when deployed on Google AppEngine?

Petrus Theron
  • 27,855
  • 36
  • 153
  • 287
  • 2
    As a workaround, you could implement the `X-HTTP-Method-Override` as Google does for their own APIs: http://googleappsdeveloper.blogspot.de/2012/03/making-patch-requests-from-app-engine.html – Philipp Reichart Apr 29 '13 at 18:20

1 Answers1

15

Just use a monkey patch by performing this before creating a WSGIApplication:

allowed_methods = webapp2.WSGIApplication.allowed_methods
new_allowed_methods = allowed_methods.union(('PATCH',))
webapp2.WSGIApplication.allowed_methods = new_allowed_methods

There is a current patch on the webapp2 issue tracker but no one has picked it up.

bossylobster
  • 9,993
  • 1
  • 42
  • 61