Opened 26 hours ago
Last modified 59 minutes ago
#36245 closed New feature
Implement Configurable Content Type Parsing `request.data` to Modernize the HTTPRequest — at Version 1
Reported by: | Adya | Owned by: | Adya |
---|---|---|---|
Component: | HTTP handling | Version: | dev |
Severity: | Normal | Keywords: | parsing, http |
Cc: | Adya | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Adding a new feature to modernize the HTTPRequest
object, adding a content-type aware request.data
property. This will parse request.body
according to the content type.
In the initial phase, I will add request.data
and add support for JSON body handling, but the next phase is to make that fully pluggable with custom parsers.
This Feature Idea is described in the Django GSoC 2025 Wiki page https://code.djangoproject.com/wiki/SummerOfCode2025#ConfigurableContentTypeParsing
This kind of feature is already implemented in *Django REST Framework* I have read the source code, DRF, Django docs, MDN reference on HTTP, and implemented it in my local Django project.
A [PlanEnglish.io Python blog](https://python.plainenglish.io/django-rest-api-tutorial-mastering-parsers-with-practical-examples-d24872c47849) described it so well.
Outcome after completing this feature
Developers will have a more streamlined and efficient way to access request data
For instance, with request.body
, a developer working with JSON data would need to write
`python
import json
data = json.loads(request.body)
user_name = data.get('name')
`
With the proposed request.data
, this simplifies to something like:
`python
user_name = request.data.get('name')
`
I am creating the test cases and patches for this implementation then PR it
Implementation Plan:
- Write test cases
- Add the request.data property to HTTPRequest.
- Implement initial JSON parsing logic.