title: How to customize the response of Django REST Framework GET request?
body: <p>I have a model <code>Foo</code> which I use as the model for my vanilla DRF serializer.</p>
  
  <p><strong>models.py</strong></p>
  
  <pre><code>class Foo(models.Model):
      name = models.CharField(max_length=20)
      description = models.TextField()
      is_public = models.BooleanField(default=False)
  </code></pre>
  
  <p><strong>serializers.py</strong></p>
  
  <pre><code>class FooSerializer(serializers.ModelSerializer):
      class Meta:
          model = Foo
  </code></pre>
  
  <p><strong>views.py</strong></p>
  
  <pre><code>class FooRetrieveAPIView(RetrieveAPIView):
      queryset = Foo.objects.all()
      serializer_class = FooSerializer
  </code></pre>
  
  <p>Now the result of this endpoint is being used by front-end code, which is then the basis on how the next page to show is identified. Anyway, I need to change the structure of the results returned for both status <code>200</code> (existing record) and <code>404</code> (non-existent record).</p>
  
  <p><strong>Actual result (from vanilla DRF):</strong></p>
  
  <pre><code>$ curl localhost:8000/foo/1/  # existing record
  {"id": 1, "name": "foo", "description": "foo description", is_public=false}
  
  $ curl localhost:8000/foo/2/  # non-existent record
  {"detail": "Not found."}
  </code></pre>
  
  <p><strong>How I want the results to be:</strong></p>
  
  <pre><code>$ curl localhost:8000/foo/1/
  {"error": "", "foo": {"id": 1, "name": "foo", "description": "foo description", is_public=false}}
  
  $ curl localhost:8000/foo/2/
  {"error": "Some custom error message", "foo": null}
  </code></pre>
  
  <p>I've mostly used vanilla DRF so things are pretty straightforward so this customization of the response structure is a bit new to me.</p>
  
  <p><em>Django version used: 1.9.9</em></p>
  
  <p><em>DRF version used: 3.3.x</em></p>