Bird
0
0

Which of the following is the correct syntax to send a 404 status code in a REST API response?

easy📝 Syntax Q12 of 15
Rest API - HTTP Status Codes
Which of the following is the correct syntax to send a 404 status code in a REST API response?
Aresponse.status(404).send('Not Found')
Bresponse.code(404).send('Not Found')
Cresponse.sendStatus(200)
Dresponse.statusCode(500).send('Error')
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct method to set status code

    In many REST frameworks, the method to set status code is status(), not code() or statusCode().
  2. Step 2: Match status code and message

    404 means 'Not Found', so response.status(404).send('Not Found') is correct syntax.
  3. Final Answer:

    response.status(404).send('Not Found') -> Option A
  4. Quick Check:

    Use status() to set code [OK]
Quick Trick: Use response.status(code) to set HTTP status [OK]
Common Mistakes:
  • Using response.code() instead of response.status()
  • Sending wrong status code for error
  • Mixing status code and message methods

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes