REST API response in partial success

a 夏天 提交于 2019-12-01 16:21:38

You may use 207 MULTI-STATUS for http status A Multi-Status response conveys information about multiple resources in situations where multiple status codes might be appropriate.

The default Multi-Status response body is a HTTP entity with a 'multistatus' root element. Further elements contain 200, 300, 400, and 500 series status codes generated during the method invocation.

You can have an array of response objects within the body of the response and those objects may have it's own status codes

Example

HTTP 207

{
    "data": [
        {
            "messgage": "success",
            "resource": {
                "foo": "bar",
                "id": "1d1"
            },
            "status": 200
        },
        {
            "messgage": "Requested resource or subresource not found ",
            "resource": null,
            "status": 404
        },
        {
            "messgage": "success",
            "resource": {
                "foo": "bars",
                "id": "1d2"
            },
            "status": 200
        }
    ],
    "metadata": {
        "failure": 1,
        "success": 2,
        "total": 3
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!