Bird
0
0

You want your REST API to return a 204 status code when a DELETE request succeeds but with no content in the response body. Which code snippet correctly implements this?

hard📝 Application Q15 of 15
Rest API - HTTP Status Codes
You want your REST API to return a 204 status code when a DELETE request succeeds but with no content in the response body. Which code snippet correctly implements this?
Ares.status(204).send();
Bres.status(204).json({ message: 'Deleted' });
Cres.sendStatus(204).json({ message: 'Deleted' });
Dres.status(200).send('Deleted');
Step-by-Step Solution
Solution:
  1. Step 1: Understand 204 status meaning

    204 means 'No Content', so the response must not include a body.
  2. Step 2: Choose code that sends 204 with no body

    res.status(204).send(); sends status 204 with empty body, which is correct. Sending JSON or message body breaks 204 rules.
  3. Final Answer:

    res.status(204).send(); -> Option A
  4. Quick Check:

    204 = no content, so send empty response [OK]
Quick Trick: 204 means no content; send empty response [OK]
Common Mistakes:
  • Sending JSON body with 204 status
  • Using 200 instead of 204 for delete success
  • Chaining json() after sendStatus(204)

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes