info http

HTTP 204 No Content

Understanding HTTP 204 No Content status code - the request succeeded but the server has no content to return in the response body.

What It Means

HTTP 204 No Content indicates that the server has successfully fulfilled the request and there is no additional content to send in the response body. The server may return updated metadata in the response headers.

This status code is commonly used for DELETE operations, PUT updates where the client doesn’t need a response body, or actions like “save and continue editing.”

Common Causes

  • A successful DELETE request that removes a resource
  • A successful PUT or PATCH request where returning the resource is unnecessary
  • A successful action that requires no response body (e.g., toggling a setting)
  • Preflight CORS responses
  • Successful form submissions that don’t redirect

How to Fix

HTTP 204 is a success code. Here’s how to use it correctly:

// Express.js - DELETE endpoint
app.delete('/api/users/:id', async (req, res) => {
  const user = await User.findById(req.params.id);
  if (!user) {
    return res.status(404).json({ error: 'User not found' });
  }
  await user.destroy();
  res.status(204).send(); // No body sent
});

// Express.js - PUT endpoint with no response body
app.put('/api/settings', async (req, res) => {
  await Settings.update(req.body);
  res.status(204).send();
});
# Django REST Framework
class UserViewSet(viewsets.ModelViewSet):
    def destroy(self, request, pk=None):
        user = get_object_or_404(User, pk=pk)
        user.delete()
        return Response(status=status.HTTP_204_NO_CONTENT)

Important notes:

  • A 204 response must not include a message body
  • Browsers will not update the document view upon receiving 204
  • Do not return JSON in the body — some clients may error on parsing an empty body
// Client-side handling
const response = await fetch('/api/users/123', { method: 'DELETE' });
if (response.status === 204) {
  // Success - no body to parse
  console.log('Resource deleted successfully');
  // Do NOT call response.json() — there is no body
}
  • HTTP 200 - OK: Use when you need to return data in the response body.
  • HTTP 201 - Created: Use when a new resource has been created.
  • HTTP 404 - Not Found: Returned when the resource to act upon does not exist.