RESTful HTTP响应代码

编程入门 行业动态 更新时间:2024-10-22 15:40:25
本文介绍了RESTful HTTP响应代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在开发一个简单的RESTful API,并完全爱上它的简约性。但我不确定各种情况下的正确HTTP响应代码:

I'm developing a simple RESTful API, and utterly in love with how minimalistic it is. But I'm uncertain as to the correct HTTP response codes for various situations:

  • 查询格式错误

  • Incorrectly formed query

    正确形成的查询是指不存在的资源

    Correctly formed query refers to a resource which does not exist

    资源已成功删除

    资源已成功修改

    我目前认为1会是 403 Forbidden ; 2将是 410 Gone ; 3和4将 202接受。他们听起来不对吗?

    I'm currently thinking that 1 would be 403 Forbidden; 2 would be 410 Gone; 3 and 4 would be 202 Accepted. Do they sound right?

    推荐答案

    对于#1,403建议您的应用程序理解请求,但不会实现它(即当前用户)由于某种原因没有权限这样做)。在这种情况下,我认为400个错误请求可能更有意义。

    For #1, 403 suggests your application understood the request, but wont fulfil it (i.e. current user doesn't have permission to do that for some reason). I think 400 bad request might make more sense in this case.

    对于#2 - 我认为404会更有意义,即找不到资源,除非资源确实存在于某个时刻,然后被删除,在这种情况下410是公平的 - 但没有多少客户知道如何处理410.

    For #2 - I would think 404 would make more sense i.e. resource is not found, unless the resource did exist at some point, and has then been deleted, in which case 410 would be fair - but not many clients know what to do with 410.

    For #3&如果您成功处理了删除,则为#4 - 200;如果删除排队,则为202,并且将在稍后带外处理。

    For #3 & #4 - 200 if you processed the deletion successfully, 202 if the deletion is queued up and will be handled at a later date "out of band".

    RFC 2616 提供了很好的解释,说明每个响应代码在可理解的术语中的含义。

    RFC 2616 provides great explanations of what each response code means in fairly understandable terms.

  • 更多推荐

    RESTful HTTP响应代码

    本文发布于:2023-11-25 09:11:48,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1629174.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:代码   RESTful   HTTP

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!