About 207 Multi-Status
Overview of 207 Multi-Status
Handling Multiple Operation ResultsHTTP Status Code | ||
207 Multi-Status Overview The 207 Multi-Status HTTP status code is used when a single request returns statuses for multiple resources. This code is primarily employed in the WebDAV protocol, where the response is formatted in XML to provide detailed information about individual resources. |
||
Meaning The client’s request returns statuses for multiple resources. |
When is 207 Multi-Status Returned?
- When WebDAV operations return results for multiple resources in a single response
- When different statuses are needed for each resource specified in the request
- When batch processing results are consolidated into a single response
Examples of 207 Multi-Status
Reporting Statuses for Multiple Resources in WebDAV
PROPFIND /files/ HTTP/1.1 Host: example.com
Response example:
HTTP/1.1 207 Multi-Status Content-Type: application/xml; charset=UTF-8 <?xml version="1.0" encoding="UTF-8"?> <multistatus xmlns="DAV:"> <response> <href>/files/file1.txt</href> <status>HTTP/1.1 200 OK</status> </response> <response> <href>/files/file2.txt</href> <status>HTTP/1.1 404 Not Found</status> </response> </multistatus>
Explanation: When a client attempts to retrieve properties for all resources within a directory, the 207 status code is returned. The response, formatted in XML, provides individual statuses for each resource.
Batch Operation Results
POST /batch HTTP/1.1 Host: example.com Content-Type: application/json { "operations": [ { "action": "delete", "resource": "/file1.txt" }, { "action": "delete", "resource": "/file2.txt" } ] }
Response example:
HTTP/1.1 207 Multi-Status Content-Type: application/json { "results": [ { "resource": "/file1.txt", "status": "200 OK" }, { "resource": "/file2.txt", "status": "404 Not Found" } ] }
Explanation: When a client requests multiple operations, and the results vary for each, the 207 status code is used. The response, formatted in JSON, provides the outcome for each resource.
Points to Note
Considerations when returning 207 Multi-Status:
- Ensure consistent response formatting
Provide results for individual resources in a consistent format, such as XML or JSON. - Clearly define individual statuses
Detail the status of each resource to allow the client to accurately parse the results.
Comparison with Related HTTP Status Codes
Explanation of HTTP status codes related to 207 Multi-Status:
- 200 OK: Indicates success for a single resource.
- 404 Not Found: Used when a specified resource cannot be found, often appearing within a 207 response for individual resources.
Understanding these differences ensures the appropriate use of the 207 status code.