Skip to content

Commit d1bb7ba

Browse files
author
Hamed Ahmadi
committed
Documenting parsing metadata in request body
1 parent b0c7488 commit d1bb7ba

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

docs/api.md

+11
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,14 @@ Calls a `get_root_meta` function on a serializer, if it exists.
4747
`build_json_resource_obj(fields, resource, resource_instance, resource_name)`
4848

4949
Builds the resource object (type, id, attributes) and extracts relationships.
50+
51+
## rest_framework_json_api.parsers.JSONParser
52+
53+
Similar to `JSONRenderer`, the `JSONParser` you may override the following methods if you need
54+
highly custom parsing control.
55+
56+
#### parse_metadata
57+
58+
`parse_metadata(result)`
59+
60+
Returns a dictionary which will be merged into parsed data of the request. By default, it reads the `meta` content in the request body and returns it in a dictionary with a `_meta` top level key.

docs/usage.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ class LineItemViewSet(viewsets.ModelViewSet):
375375

376376
### RelationshipView
377377
`rest_framework_json_api.views.RelationshipView` is used to build
378-
relationship views (see the
378+
relationship views (see the
379379
[JSON API spec](http://jsonapi.org/format/#fetching-relationships)).
380380
The `self` link on a relationship object should point to the corresponding
381381
relationship view.
@@ -449,6 +449,8 @@ def get_root_meta(self, resource, many):
449449
```
450450
to the serializer. It must return a dict and will be merged with the existing top level `meta`.
451451

452+
To access metadata in incoming requests, the `JSONParser` will add the metadata under a top level `_meta` key in the parsed data dictionary. For instance, to access meta data from a `serilizer` object, you may use `serializer.initial_data.get("_meta")`. To customize the `_meta` key, see [here](api.md).
453+
452454
### Links
453455

454456
Adding `url` to `fields` on a serializer will add a `self` link to the `links` key.

0 commit comments

Comments
 (0)