Skip to content

Add input parsing #28

Open
Open
@jsocol

Description

@jsocol

A simple decorator that would do something like this:

# POST {"foo": "bar"}
@json_request
def my_view(request):
    assert request.META['CONTENT_TYPE'] == 'application/json'
    assert request.data == {'foo': 'bar'}

Not 100% sure how to handle other content-types yet. That's probably got to go into some sort of setting. Do you always want to assume JSON (e.g. try to parse it regardless of the content-type header) or respect the header? If it does respect the header, does it make sense to assign request.data = request.POST if content-type is set to application/x-www-form-urlencoded? What's the right error-handling if you can't parse JSON (or form-encoded)? 400?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions