May 2018
Beginner to intermediate
526 pages
11h 57m
English
The serialized data has to be rendered in a specific format before you return it in an HTTP response. Likewise, when you get an HTTP request, you have to parse the incoming data and de-serialize it before you can operate with it. REST framework includes renderers and parsers to handle that.
Let's see how to parse incoming data. Execute the following code in the Python shell:
>>> from io import BytesIO>>> from rest_framework.parsers import JSONParser>>> data = b'{"id":4,"title":"Programming","slug":"programming"}'>>> JSONParser().parse(BytesIO(data)){'id': 4, 'title': 'Programming', 'slug': 'programming'}
Given a JSON string input, you can use the JSONParser class provided by REST framework to convert it ...
Read now
Unlock full access