Bird
0
0

What is the issue with this Node.js Express code snippet when sending a 204 No Content response?

medium📝 Debug Q6 of 15
Rest API - HTTP Status Codes
What is the issue with this Node.js Express code snippet when sending a 204 No Content response?
res.status(204).json({ success: true });
A204 responses must not include a response body, so sending JSON is incorrect
BThe status code 204 is invalid for JSON responses
CThe .json() method automatically changes status to 200
DNo issue; this is a valid way to send a 204 response
Step-by-Step Solution
Solution:
  1. Step 1: Understand 204 semantics

    204 means no content; sending JSON violates this rule.
  2. Step 2: Express behavior

    .json() sends a response body, which is disallowed with 204.
  3. Final Answer:

    204 responses must not include a response body, so sending JSON is incorrect -> Option A
  4. Quick Check:

    204 cannot have body content [OK]
Quick Trick: 204 status must not send any response body [OK]
Common Mistakes:
MISTAKES
  • Sending JSON or any body with 204
  • Assuming .json() changes status code
  • Ignoring HTTP spec for 204 responses

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes