0

I'm fetching todos, if database has todos I return 200 status code, but if database has no todo then which status code should I return?

if(!todos->isEmpty()){
    return response()->json(['todos' => $todos], 200);
}
else{
    return response()->json(['todos' => 'No Todos'], 404);
    // OR
    //return response()->json(['todos' => NULL], 404);
    // OR
    //return response()->json(['todos' => NULL], 200);
    // OR
    //return response()->json(['todos' => array()], 404);
    // OR
    //return response()->json(['todos' => array()], 200);
}
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
  • Please Reff this link : http://stackoverflow.com/questions/11746894/what-is-the-proper-rest-response-code-for-a-valid-request-but-an-empty-data – Mohammad Faizan Apr 23 '17 at 07:19
  • Empty array, 200 OK. The request works just fine and the endpoint exists. Also I think this means you can get rid of the `if` entirely. – jonrsharpe Apr 23 '17 at 07:41
  • Possible duplicate of [What is the proper REST response code for a valid request but an empty data?](http://stackoverflow.com/questions/11746894/what-is-the-proper-rest-response-code-for-a-valid-request-but-an-empty-data) – Kalana Demel May 06 '17 at 03:34

0 Answers0