So far, our RESTful Web Service has been working with JSON for the response body. The code we wrote in the
toys/views.py file in Chapter 3, Creating API Views, declares a
JSONResponse class and two function-based views. These functions return a
JSONResponse when it is necessary to return JSON data and a
django.Http.Response.HttpResponse instance when the response is just an HTTP status code. No matter the accepted content type specified in the HTTP request header, the view functions always provide the same content in the response body: JSON.
Run the following command to retrieve all the toys with the
Accept request header key set to
text/html. Remember that the virtual environment we have created in Chapter 3, Creating API Views, must be activated in order to run the next
http :8000/toys/ Accept:text/html
The following is the equivalent
curl -H "Accept: text/html" -iX GET localhost:8000/toys/
The previous commands...