Subscribe to PHP Freaks RSS

207 Multi-Status

syndicated from planet-php.net on August 21, 2018

207 Multi-Status is used primarily by WebDAV servers. I don’t think it’s used much outside of WebDAV, if at all.



The WebDAV specification describes this statuscode as an indicator to a client that multiple operations happened, and that the status for each operation can be found in the body of the response.



So unlike other 2xx codes, getting a 207 doesn’t necessarily mean the operation succeeded. It just means that the client should inspect the body to get the true information about the operation.



The most common WebDAV example is that it has a feature to get information about multiple resources all at once via the PROPFIND HTTP method. The server can then report information about each individual resource via this code.



Here’s an example of a typical 207 response:



HTTP/1.1 207 Multi-Status
Content-Type: application/xml; charset="utf-8"
Content-Length: xxxx

<d:multistatus xmlns:d="DAV:"> <d:response> <d:href>/calendars/johndoe/home/132456762153245.ics</d:href> <d:propstat> <d:prop> <d:getetag>"xxxx-xxx"</d:getetag> </d:prop> <d:status>HTTP/1.1 200 OK</d:status> </d:propstat> </d:response> <d:response> <d:href>/calendars/johndoe/home/fancy-caldav-client-1234253678.ics</d:href> <d:propstat> <d:prop> <d:getetag>"5-12"</d:getetag> </d:prop> <d:status>HTTP/1.1 200 OK</d:status> </d:propstat> </d:response> </d:multistatus>


In the preceeding response, 2 resources are reported and for each a getetag WebDAV property is reported. Fully explaining the WebDAV model is outside the scope of this article.



You could imagine that 207 might be repurposed by some JSON-based API. For example, if a client made some kind of batch request, and a server wants to report back on the success of each individual item.



Perhaps this response looks somewhat like this:



HTTP/1.1 207 Multi-Status
Content-Type: application/json
Content-Length: xxxx

{ "results": [ { "href": "/batch/5/item/1", "status": 200 }, { "href": "/batch/5/item/2", "status"

Truncated by Planet PHP, read more at the original (another 2151 bytes)