I have an endpoint that returns a list of products.
So, if there's any data in this list, I'll set the HTTP status code to 200, and if it does not, I just return a json saying that no record was found and the status code of HTTP 200.
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 concerns are related to the HTTP status code.
Questions
200 OK
.