Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
817 views
in Technique[技术] by (71.8m points)

rest - What is the HTTP response code for failed HTTP Delete operation?

I have a resources with uri /api/books/122 , if this resource doesn't exist at the point where a client sends HTTP Delete for this resource, what is the appropriate response code from this action? Is it 404 Not Found?
Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The response code for a delete call can be any of the following :

  • DELETE /api/book/122 - The server successfully processed the request, but is not returning any content
    • 204 No Content
  • DELETE /api/book/122 - Resource does not exist
    • 404 Not Found
  • DELETE /api/book/122 - Resource already deleted
    • 410 Gone
  • DELETE /api/book/122 - Users does not have permission

    • 403 Forbidden
  • DELETE /api/book/122 - Method Not Allowed

    • 405 Method Not Allowed
  • DELETE /api/book/122 - Conflict (User can resolve the conflict and delete)

    • 409 Conflict

In your case 404 is apt.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...