0
0
Rest APIprogramming~20 mins

Retry-After header in Rest API - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Retry-After Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
1:30remaining
What is the output of this HTTP response header?

Consider a server response with the following HTTP header:

Retry-After: 120

What does the value 120 represent?

AThe client should retry the request after 120 seconds.
BThe client should retry the request after 120 milliseconds.
CThe client should retry the request after 120 minutes.
DThe client should retry the request immediately.
Attempts:
2 left
💡 Hint

Think about the unit of time used in the Retry-After header when a number is given.

🧠 Conceptual
intermediate
1:30remaining
What type of value can the Retry-After header contain?

The Retry-After header can have two types of values. Which of the following correctly describes them?

AOnly a HTTP-date timestamp.
BOnly a number of seconds.
CA number of seconds or a HTTP-date timestamp.
DA boolean value true or false.
Attempts:
2 left
💡 Hint

Think about how servers can tell clients when to retry: either a delay or a specific time.

🔧 Debug
advanced
2:00remaining
Identify the error in this Retry-After header usage

A server sends this header:

Retry-After: 2024-13-01T12:00:00Z

What is wrong with this header value?

AThe Retry-After header cannot contain a date, only seconds.
BThe month value 13 is invalid in the date format.
CThe time zone Z is not allowed in HTTP-date format.
DThe date format is correct and valid.
Attempts:
2 left
💡 Hint

Check the month part of the date carefully.

🚀 Application
advanced
2:00remaining
How should a client handle a Retry-After header with a date value?

A client receives this header:

Retry-After: Wed, 21 Oct 2025 07:28:00 GMT

What should the client do?

ACalculate the difference between the current time and the given date, then wait that long before retrying.
BIgnore the header and retry immediately.
CRetry after 21 seconds as indicated by the day number.
DRetry after 7 minutes and 28 seconds.
Attempts:
2 left
💡 Hint

Think about how to interpret a date in the Retry-After header.

Predict Output
expert
3:00remaining
What is the output of this Python code parsing Retry-After header?

Given this Python code snippet:

from datetime import datetime, timezone
import time

def parse_retry_after(value):
    try:
        delay = int(value)
        return delay
    except ValueError:
        retry_time = datetime.strptime(value, '%a, %d %b %Y %H:%M:%S %Z')
        now = datetime.now(timezone.utc)
        delta = (retry_time - now).total_seconds()
        return max(0, int(delta))

# Example usage:
print(parse_retry_after('120'))
print(parse_retry_after('Wed, 21 Oct 2030 07:28:00 GMT'))

Assuming the current UTC time is Wed, 21 Oct 2025 07:28:00 GMT, what will be the output?

Rest API
from datetime import datetime, timezone
import time

def parse_retry_after(value):
    try:
        delay = int(value)
        return delay
    except ValueError:
        retry_time = datetime.strptime(value, '%a, %d %b %Y %H:%M:%S %Z')
        now = datetime.now(timezone.utc)
        delta = (retry_time - now).total_seconds()
        return max(0, int(delta))

# Example usage:
print(parse_retry_after('120'))
print(parse_retry_after('Wed, 21 Oct 2030 07:28:00 GMT'))
AValueError exception
B
120
0
C
120
-157766400
D
120
157766400
Attempts:
2 left
💡 Hint

Calculate the seconds between 2025 and 2030 in years, then convert to seconds.