7
I own an endpoint that returns a list of products.
Therefore, if there is data from this list I set the HTTP status code to 200, and if there is not, I return only a json saying that no record has been found and the HTTP 200 status code.
My endpoint:
http://api.minhaappexemplo.com.br/rest/lista/1/minha111chave222
My routine responsible for this endpoint, see:
<?php
$app->get('/rest/lista/{id}/{key}',
function(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response, $next)
{
$id = $request->getAttribute("id");
$listaProdutos = Lista::obterListaProdutos($id);
if ($listaProdutos)
{
return $response->withJson($listaProdutos, 200);
}
else
{
return $response->withJson(array("resposta" => 'Nenhum registro encontrado.'), 200);
}
}
)->add(new MiddlewareApiKeyCheck());
My questions are related to HTTP status code.
Doubts
- Is there any HTTP status code that can be used in situations that no records to return to client/browser?
- Can I use status code 200 in these situations? Since the
successful request status must be
200 OK
.