Bird
0
0

Which of the following is the correct way to respond with a 422 status code in a REST API using Express.js (Node.js)?

easy📝 Syntax Q12 of 15
Rest API - HTTP Status Codes
Which of the following is the correct way to respond with a 422 status code in a REST API using Express.js (Node.js)?
Ares.sendStatus(404);
Bres.status(200).json({ message: 'Success' });
Cres.status(500).json({ error: 'Server error' });
Dres.status(422).send('Invalid input data');
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct status code usage

    To send a 422 status, use res.status(422) in Express.js.
  2. Step 2: Confirm response method

    Using .send() or .json() after setting status sends the response properly.
  3. Final Answer:

    res.status(422).send('Invalid input data'); -> Option D
  4. Quick Check:

    Express 422 response = res.status(422).send() [OK]
Quick Trick: Use res.status(422) to set code before sending response [OK]
Common Mistakes:
  • Using wrong status code like 404 or 500
  • Forgetting to set status before sending response
  • Sending 200 OK for invalid data

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes