Bird
0
0

A developer wrote this Express.js code to send a 204 response:

medium📝 Debug Q14 of 15
Rest API - HTTP Status Codes
A developer wrote this Express.js code to send a 204 response:
app.delete('/item/:id', (req, res) => {
  res.status(204).send({ message: 'Deleted' });
});
What is the problem with this code regarding the 204 No Content response?
A204 responses must not include a response body, but this sends JSON content.
BThe status code should be 200 instead of 204 for delete operations.
CThe route method should be GET, not DELETE.
DThe response is missing a Content-Type header.
Step-by-Step Solution
Solution:
  1. Step 1: Understand 204 No Content rules

    204 status means no response body should be sent, but the code sends JSON content in the body.
  2. Step 2: Identify the violation in the code

    Calling send() with an object adds a response body, which violates 204 semantics.
  3. Final Answer:

    204 responses must not include a response body, but this sends JSON content. -> Option A
  4. Quick Check:

    204 must not send body [OK]
Quick Trick: Never send body with 204 status [OK]
Common Mistakes:
  • Sending JSON or text body with 204 status
  • Using wrong HTTP method for delete
  • Confusing 204 with 200 OK

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes