aboutsummaryrefslogtreecommitdiffstats
path: root/docs/api-guide/parsers.md
diff options
context:
space:
mode:
authorTom Christie2012-10-15 13:27:50 +0100
committerTom Christie2012-10-15 13:27:50 +0100
commit9c1fba3483b7e81da0744464dcf23a5f12711de2 (patch)
treed9370dc9fb9d2fea65192bf5ce4d7fb594d3ad0c /docs/api-guide/parsers.md
parente88ca9637bd4f49659dd80ca7afd0f38adf07746 (diff)
downloaddjango-rest-framework-9c1fba3483b7e81da0744464dcf23a5f12711de2.tar.bz2
Tweak parsers to take parser_context
Diffstat (limited to 'docs/api-guide/parsers.md')
-rw-r--r--docs/api-guide/parsers.md26
1 files changed, 14 insertions, 12 deletions
diff --git a/docs/api-guide/parsers.md b/docs/api-guide/parsers.md
index 4b769672..4f145ba3 100644
--- a/docs/api-guide/parsers.md
+++ b/docs/api-guide/parsers.md
@@ -65,7 +65,7 @@ Parses `YAML` request content.
Parses REST framework's default style of `XML` request content.
-Note that the `XML` markup language is used typically used as the base language for more strictly defined domain-specific languages, such as `RSS`, `Atom`, `SOAP`, and `XHTML`.
+Note that the `XML` markup language is used typically used as the base language for more strictly defined domain-specific languages, such as `RSS`, `Atom`, and `XHTML`.
If you are considering using `XML` for your API, you may want to consider implementing a custom renderer and parser for your specific requirements, and using an existing domain-specific media-type, or creating your own custom XML-based media-type.
@@ -95,7 +95,19 @@ To implement a custom parser, you should override `BaseParser`, set the `.media_
The method should return the data that will be used to populate the `request.DATA` property.
-For example:
+The arguments passed to `.parse_stream()` are:
+
+### stream
+
+A stream-like object representing the body of the request.
+
+### parser_context
+
+If supplied, this argument will be a dictionary containing any additional context that may be required to parse the request content. By default it includes the keys `'upload_handlers'` and `'meta'`, which contain the values of the `request.upload_handlers` and `request.meta` properties.
+
+## Example
+
+The following is an example plaintext parser that will populate the `request.DATA` property with a string representing the body of the request.
class PlainTextParser(BaseParser):
"""
@@ -110,16 +122,6 @@ For example:
"""
return stream.read()
-The arguments passed to `.parse_stream()` are:
-
-### stream
-
-A stream-like object representing the body of the request.
-
-### parser_context
-
-If supplied, this argument will be a dictionary containing any additional context that may be required to parse the request content. By default it includes the keys `'upload_handlers'` and `'meta'`, which contain the values of the `request.upload_handlers` and `request.meta` properties.
-
## Uploading file content
If your custom parser needs to support file uploads, you may return a `DataAndFiles` object from the `.parse_stream()` method. `DataAndFiles` should be instantiated with two arguments. The first argument will be used to populate the `request.DATA` property, and the second argument will be used to populate the `request.FILES` property.