REST API response in partial success

后端 未结 1 1881
遇见更好的自我
遇见更好的自我 2021-01-07 23:44

I have an API which does some bulk processing task. Let\'s say it does naming of some resource.

I passed 7 request in bulk, out of which 5 updated successfully and 2

1条回答
  •  悲哀的现实
    2021-01-08 00:04

    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
        }
    }
    

    0 讨论(0)
提交回复
热议问题