Bird
0
0

Which of the following is the correct way to send a 201 Created status code in a Node.js Express REST API?

easy📝 Syntax Q3 of 15
Rest API - HTTP Status Codes
Which of the following is the correct way to send a 201 Created status code in a Node.js Express REST API?
Ares.sendStatus(201);
Bres.status(201).json({ message: 'Created' });
CAll of the above
Dres.status(201).send('Created');
Step-by-Step Solution
Solution:
  1. Step 1: Understand Express response methods

    res.sendStatus sets status and sends text, res.status sets status and allows chaining send or json.
  2. Step 2: Check each option

    All options correctly send a 201 status with a response.
  3. Final Answer:

    All of the above -> Option C
  4. Quick Check:

    Multiple ways to send 201 = B [OK]
Quick Trick: Express allows multiple ways to send status and response [OK]
Common Mistakes:
MISTAKES
  • Using res.send without status
  • Not chaining status before send
  • Sending status code as string

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes