#32646 closed New feature (duplicate)
add request.json() shortcut
Reported by: | Collin Anderson | Owned by: | nobody |
---|---|---|---|
Component: | HTTP handling | Version: | 4.0 |
Severity: | Normal | Keywords: | |
Cc: | Adam Johnson | Triage Stage: | Unreviewed |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
It would be nice to have a request.json() shortcut.
Change History (5)
comment:1 Changed 3 years ago by
comment:2 Changed 3 years ago by
Resolution: | → duplicate |
---|---|
Status: | new → closed |
As far as I'm aware, it's a duplicate of #27415.
comment:3 Changed 3 years ago by
Cc: | Adam Johnson added |
---|
I think this also relates to #32259. Completing the content negotiation story as suggested on #27415 would be the significant benefits justifying changes in #32259. 🤔
comment:4 Changed 3 years ago by
There's also #21442 for Tom Christie's work.
I think adding request.json()
would be a bit of a mis-feature, when we could instead add request.data
with a parsing framework that's more "future-proof". It would be based on DRF's behaviour, so would be familiar to most Django devs already.
comment:5 Changed 3 years ago by
I can see the case for content negotiation.
My two cents: In browsers, there's a standard .json()
method for http responses [0], and the Python requests
library also has .json()
method, so a simple .json()
method is becoming more of the norm for a lot of simple use cases.
I don't think I'd be wrong if I said most apis only need to speak json. Content negotiation, while needed for some use cases, is probably overkill for many people's. Some people aren't going to want their endpoint to accept xml and yaml.
[0] https://developer.mozilla.org/en-US/docs/Web/API/Body/json
PR: https://github.com/django/django/pull/14258