In REST API design, which HTTP status code best represents a partial success response?
Think about a status code that can represent multiple outcomes in one response.
The 207 Multi-Status code is used to convey information about multiple resources, often indicating partial success.
Given this JSON response from a REST API after batch processing, what is the value of results[1].status?
{
"results": [
{"id": 1, "status": "success"},
{"id": 2, "status": "failed", "error": "Invalid input"},
{"id": 3, "status": "success"}
]
}Look carefully at the second item in the results array.
The second item has a status field with the value "failed" indicating partial failure.
When a batch REST API call partially succeeds, which approach is best to inform the client?
Consider how to communicate both successes and failures clearly.
Returning HTTP 200 with detailed results allows clients to see which items succeeded or failed.
What error will this Python Flask code produce when handling partial success?
from flask import Flask, jsonify
app = Flask(__name__)
@app.route('/batch', methods=['POST'])
def batch_process():
results = [{"id": 1, "status": "success"}, {"id": 2, "status": "failed"}]
if any(r['status'] == 'failed' for r in results):
return jsonify(results), 207
else:
return jsonify(results), 200
if __name__ == '__main__':
app.run()Check if Flask supports status code 207 and if jsonify can handle the data.
Flask supports custom status codes like 207, and jsonify can serialize lists of dictionaries, so no error occurs.
Given this Python code that filters partial success results, how many items remain in success_items?
responses = [
{"id": 1, "status": "success"},
{"id": 2, "status": "failed"},
{"id": 3, "status": "success"},
{"id": 4, "status": "failed"},
{"id": 5, "status": "success"}
]
success_items = [r for r in responses if r['status'] == 'success']
print(len(success_items))Count how many items have status 'success'.
There are three items with status 'success' (id 1, 3, and 5), so the length is 3.