joomla-cms icon indicating copy to clipboard operation
joomla-cms copied to clipboard

[5.3] DELETE should return 204 if item don't exist

Open alikon opened this issue 6 months ago • 7 comments

Pull Request for Issue # .

Summary of Changes

According to the HTTP/REST specification, a DELETE request for a resource that does not exist should respond with 204 No Content or 404 Not Found.

Testing Instructions

execute a DELETE api/index.php/v1/content/articles/99 for a non existent item

Actual result BEFORE applying this Pull Request

{ "errors": [ { "code": 500, "title": "Internal server error" } ] }

Expected result AFTER applying this Pull Request

return 204

Link to documentations

Please select:

  • [ ] Documentation link for docs.joomla.org:

  • [ ] No documentation changes for docs.joomla.org needed

  • [ ] Pull Request link for manual.joomla.org:

  • [ ] No documentation changes for manual.joomla.org needed

alikon avatar Jun 10 '25 09:06 alikon

@alikon The title and the expected result say "204". Did you mean "404"?

richard67 avatar Jun 10 '25 09:06 richard67

no i mean http status code 204 https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/204

alikon avatar Jun 10 '25 09:06 alikon

no i mean http status code 204 https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/204

I see. Thanks for clarification.

richard67 avatar Jun 10 '25 09:06 richard67

@alikon Would it not be great to have this in System Tests?

muhme avatar Jun 11 '25 07:06 muhme

@muhme did you mean like that ?

alikon avatar Jun 13 '25 10:06 alikon

@alikon Thank you for adding single System Tests :+1: As this counts for all ressouces, should we add the test everywhere? Or, if this is too expensive, creating one new test like checking-api-status?

And sorry for jumping in at the end — from what I understand, 204 'No Content' is used when a resource is successfully deleted, so there’s nothing to return. If the resource doesn’t exist, then 404 'Not Found' would be the appropriate response — wouldn’t it?

muhme avatar Jun 13 '25 14:06 muhme

@muhme

As this counts for all ressouces, should we add the test everywhere? Or, if this is too expensive, creating one new test like checking-api-status?

consider that some api test even don't test the delete endpoint , so don't know what's better

And sorry for jumping in at the end — from what I understand, 204 'No Content' is used when a resource is successfully deleted, so there’s nothing to return. If the resource doesn’t exist, then 404 'Not Found' would be the appropriate response — wouldn’t it?

According to the HTTP/REST specification, a DELETE request for a resource that does not exist should respond with 204

alikon avatar Jun 13 '25 14:06 alikon

I have tested this item :white_check_mark: successfully on 3ac675a5bcc68db9204ef80e79c755ce1a774b84

I have successfully tested this!! Thanks @alikon!


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/45589.

exlemor avatar Aug 23 '25 10:08 exlemor

I have tested this item :white_check_mark: successfully on 3ac675a5bcc68db9204ef80e79c755ce1a774b84

  • Tested in using JBT, before the PR, with curl:
    • Created API Token and stored in TOKEN env var
    • Created three articles and trashed them
    • Existing article can be deleted and ends in status code 204
    • Non-existing article ends in status code 500
  • After applying the patch with graft
    • Created three articles and trashed them
    • Existing article can be deleted and ends in status code 204 "No Content"
    • Non-existing article ends in status code 204 "No Content"
    • Wrong api/index.php/v1/content/articles/a ends in status code 404 "Resource not found"

curl sample:

curl -v --header "X-Joomla-Token: $TOKEN" -X DELETE "http://localhost:7053/api/index.php/v1/content/articles/42"
...
< HTTP/1.1 500 Internal Server Error
...
{"errors":[{"code":500,"title":"Internal server error"}]}%   
```<hr /><sub>This comment was created with the <a href="https://github.com/joomla/jissues">J!Tracker Application</a> at <a href="https://issues.joomla.org/tracker/joomla-cms/45589">issues.joomla.org/tracker/joomla-cms/45589</a>.</sub>

muhme avatar Aug 23 '25 15:08 muhme

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/45589.

richard67 avatar Aug 23 '25 15:08 richard67

Thanks

rdeutz avatar Aug 25 '25 12:08 rdeutz