API: add DELETE endpoint
Based on #840 See http://shaarli.github.io/api-documentation/\#links-link-delete
This commit is contained in:
parent
cf9181dddf
commit
0843848c1d
4 changed files with 168 additions and 40 deletions
application/api/controllers
|
@ -188,4 +188,27 @@ class Links extends ApiController
|
|||
$out = ApiUtils::formatLink($responseLink, $index);
|
||||
return $response->withJson($out, 200, $this->jsonStyle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an existing link by its ID.
|
||||
*
|
||||
* @param Request $request Slim request.
|
||||
* @param Response $response Slim response.
|
||||
* @param array $args Path parameters. including the ID.
|
||||
*
|
||||
* @return Response response.
|
||||
*
|
||||
* @throws ApiLinkNotFoundException generating a 404 error.
|
||||
*/
|
||||
public function deleteLink($request, $response, $args)
|
||||
{
|
||||
if (! isset($this->linkDb[$args['id']])) {
|
||||
throw new ApiLinkNotFoundException();
|
||||
}
|
||||
|
||||
unset($this->linkDb[(int) $args['id']]);
|
||||
$this->linkDb->save($this->conf->get('resource.page_cache'));
|
||||
|
||||
return $response->withStatus(204);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue