0
0
Rest APIprogramming~20 mins

Partial success handling in Rest API - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Partial Success Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
1:00remaining
What is the HTTP status code for partial success in REST APIs?

In REST API design, which HTTP status code best represents a partial success response?

A207 Multi-Status
B500 Internal Server Error
C404 Not Found
D200 OK
Attempts:
2 left
💡 Hint

Think about a status code that can represent multiple outcomes in one response.

Predict Output
intermediate
1:00remaining
What is the output of this partial success JSON response?

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"}
  ]
}
A"failed"
Bnull
C"success"
D"pending"
Attempts:
2 left
💡 Hint

Look carefully at the second item in the results array.

🧠 Conceptual
advanced
1:30remaining
Which approach best handles partial success in batch REST API calls?

When a batch REST API call partially succeeds, which approach is best to inform the client?

AReturn HTTP 500 to indicate failure of the entire batch
BReturn HTTP 404 if any item is not found
CReturn HTTP 200 with a detailed body showing success and failure per item
DReturn HTTP 204 No Content with no details
Attempts:
2 left
💡 Hint

Consider how to communicate both successes and failures clearly.

🔧 Debug
advanced
1:30remaining
Identify the error in this partial success response handler code snippet

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()
ARuntimeError because jsonify cannot serialize list of dicts
BNo error; code runs and returns 207 status with JSON
CSyntaxError due to missing colon after if statement
DTypeError because 207 is not a valid HTTP status code in Flask
Attempts:
2 left
💡 Hint

Check if Flask supports status code 207 and if jsonify can handle the data.

🚀 Application
expert
1:30remaining
How many items are in the final success list after partial success filtering?

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))
A0
B2
C5
D3
Attempts:
2 left
💡 Hint

Count how many items have status 'success'.