API: add DELETE endpoint

Based on 

See http://shaarli.github.io/api-documentation/\#links-link-delete
This commit is contained in:
ArthurHoaro 2017-05-06 17:32:16 +02:00
parent cf9181dddf
commit 0843848c1d
4 changed files with 168 additions and 40 deletions
application/api/controllers

View file

@ -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);
}
}