• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer

REST API Tutorial

  • REST
  • JSON
  • Dark Mode
Home / HTTP Status / HTTP Status 204 (No Content)

HTTP Status 204 (No Content)

HTTP Status 204 (No Content) indicates that the server has successfully fulfilled the request and that there is no content to send in the response payload body. The server might want to return updated meta-information in the form of entity-headers, which, if present, SHOULD be applied to the current document’s active view if any.

The 204 response MUST NOT include a message-body and thus is always terminated by the first empty line after the header fields.

By default, 204 (No Content) response is cacheable. If caching needs to be overridden then response must include cache respective cache headers.

For example, you may want to return status 204 (No Content) in UPDATE operations where request payload is large enough not to transport back and forth. The user agent will send the payload to the server to update the resource. If the operation is successful, the server will respond with 204 to indicate the success so that client application can update its UI to inform the user about the operation’s success.

It is also frequently used with interfaces that expect automated data transfers to be prevalent, such as within distributed version control systems.

Resolving lost update problem

With status 204, server may also include HTTP header ETag to let the client validate client side resource representation before making further update on server – to avoid lost update problem.

Lost update problem happens when multiple people edit a resource without knowledge of each other’s changes. In this scenario, the last person to update a resource “wins,” and previous updates are lost. ETags can be used in combination with the If-Match header to let the server decide if a resource should be updated. If ETag does not match then server informs the client via a 412 (Precondition Failed) response.

Reference: 204 No Content

Was this article helpful?

TwitterFacebookLinkedInReddit
Previous Tutorial:
HTTP Status 202 (Accepted)
Next Tutorial:
HTTP Status 301 (Moved Permanently)

Reader Interactions

Comments

  1. rajsekhar mahapatro says

    August 23, 2018 at 1:54 am

    Hi for a request i am returning a certain type of Object say a City object, now if i make a request for a resource which doesn’t exists now how to handle the no content request? Remember i am returning a City Object.

    Reply
    • Marc Donovan says

      September 4, 2018 at 6:31 pm

      that’s a 404, not a 204

      Reply
      • Jeroen Verschuuren says

        August 28, 2019 at 8:45 am

        Depends on what you asked for:
        If you requested a list of a sub-resource then I would return a 204 – No content
        (e.g. https://api.somebookstore.com/authors/123/books)

        If you requested a single (sub-)resource then I would return a 404 – Not found
        (e.g. https://api.somebookstore.com/authors/123/books/345)

        Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Search Tutorials

Learn REST

  • What is REST?
  • REST Constraints
  • REST Resource Naming Guide

Guides

  • Caching
  • Compression
  • Content Negotiation
  • HATEOAS
  • Idempotence
  • Security Essentials
  • Versioning
  • Statelessness in REST APIs

Tech – How To

  • REST API Design Tutorial
  • Create REST APIs with JAX-RS

FAQs

  • PUT vs POST
  • N+1 Problem
  • ‘q’ Parameter

Resources

  • What is an API?
  • Comparing SOAP vs REST APIs
  • HTTP Methods
  • Richardson Maturity Model
  • HTTP Response Codes
    • 200 (OK)
    • 201 (Created)
    • 202 (Accepted)
    • 204 (No Content)
    • 301 (Moved Permanently)

Footer

References

  • The dissertation by Roy Thomas Fielding
  • Uniform Resource Identifier (URI, URL, URN) [RFC 3986]
  • Internet MediaTypes
  • Web Application Description Language (WADL)

Meta Links

  • About
  • Contact Us
  • Privacy Policy

Blogs

  • How To Do In Java

Copyright © 2020 · restfulapi.net · All Rights Reserved. | Sitemap