zhaomin zhaomin - 1 year ago 94
reST (reStructuredText) Question

web2py request.post_vars missing in HTTP PATCH

I'm looking to make use of HTTP PATCH to update a single field in a record (distinguishing this from PUT which should update the entire record). However it appears that post_vars (which I plan to hold the updated fields) does not get parsed in the request object due to this line in parse_post_vars in gluon/globals.py:

and env.request_method in ('POST', 'PUT', 'DELETE', 'BOTH')):

Is there a reason that we don't have PATCH in that list?

Answer Source

Note, request.post_vars is intended to be a dictionary-like object (derived from form data or JSON), but a patch document need not be. For example, if you send a patch of type application/json-patch+json as described here, the resulting Python object would be a list.

Because the format of patch documents is flexible, you should handle parsing and applying them on your own. You can always read the patch document directly via request.body.read().

I suppose web2py could automatically parse a patch document of type application/merge-patch+json (as described here). Feel free to post to the developer's list about that possibility.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download