From 0843848c1d18e92504c43d181063a2012f8fd5b9 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sat, 6 May 2017 17:32:16 +0200 Subject: API: add DELETE endpoint Based on #840 See http://shaarli.github.io/api-documentation/\#links-link-delete --- application/api/controllers/Links.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'application') diff --git a/application/api/controllers/Links.php b/application/api/controllers/Links.php index 1c68b062..a40e974d 100644 --- a/application/api/controllers/Links.php +++ b/application/api/controllers/Links.php @@ -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); + } } -- cgit v1.2.3