try to follow to HATEOAS.
This commit is contained in:
@@ -19,12 +19,22 @@ final class View
|
||||
return api_error('No id was given.', HTTP_STATUS::HTTP_BAD_REQUEST);
|
||||
}
|
||||
|
||||
$apiUrl = $request->getUri()->withHost('')->withPort(0)->withScheme('');
|
||||
|
||||
$task = TasksCommand::getTasks($id);
|
||||
|
||||
if (empty($task)) {
|
||||
return api_error('Task not found.', HTTP_STATUS::HTTP_NOT_FOUND);
|
||||
}
|
||||
|
||||
return api_response(Index::formatTask($task), HTTP_STATUS::HTTP_OK);
|
||||
$response = [
|
||||
...Index::formatTask($task),
|
||||
'links' => [
|
||||
'self' => (string)$apiUrl,
|
||||
'list' => (string)$apiUrl->withPath(parseConfigValue(Index::URL)),
|
||||
],
|
||||
];
|
||||
|
||||
return api_response($response, HTTP_STATUS::HTTP_OK);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user