QuizzesCalling External APIs — httpx.AsyncClient Patterns — Concept Check
intermediate
fastapi

Calling External APIs — httpx.AsyncClient Patterns — Concept Check

Questions on Calling External APIs — httpx.AsyncClient Patterns. One shared AsyncClient (from lifespan) with explicit timeouts, raise_for_status handling, asyncio.gather for fan-out, and retries with backoff — the toolkit for every payment, SMS, and partner API you'll ever call.

7 minutes 7 questions Pass at 70%
Time Limit
7 minutes - timer starts when you begin
Change Answers Freely
Revisit and change any answer before submitting
Full Review After Submit
Correct answers and explanations shown for every question
Auto-submit on timeout
Quiz submits automatically when time runs out

Questions in this quiz

7 questions on Calling External APIs — httpx.AsyncClient Patterns — Concept Check. Work through them here, then start the quiz to answer them and see your score.

  1. 1.A service using httpx.AsyncClient is experiencing slow response times. What could be a likely cause if connection pooling is not reused?

    • AThe timeout settings are too short.
    • BThe requests are not idempotent.
    • CEach request initiates a new TCP+TLS handshake.
    • DThe service is rate-limited by the upstream.
  2. 2.When using asyncio.gather with return_exceptions=True, what happens if one of the upstream calls fails?

    • AThe entire operation fails.
    • BAll other calls are cancelled.
    • CThe failed call retries automatically.
    • DThe failed call's exception is returned in place of its result.
  3. 3.A developer retries a POST request without idempotency keys after a timeout. What risk does this pose?

    • AThe request will be ignored by the server.
    • BThe request will succeed without issues.
    • CThe server will automatically handle duplicates.
    • DIt may result in duplicate operations.
  4. 4.A service encounters frequent 502 errors from an upstream API. What is a recommended approach?

    • AIgnore the errors as they are transient.
    • BSwitch to a synchronous HTTP client.
    • CImplement retries with exponential backoff and jitter.
    • DIncrease the timeout settings indefinitely.
  5. 5.When should you use asyncio.gather for API calls?

    • AWhen calls are independent and can be overlapped.
    • BWhen calls depend on each other's results.
    • CWhen calls must be executed sequentially.
    • DWhen calls require different timeout settings.
  6. 6.What is the role of explicit timeouts in httpx.AsyncClient?

    • ATo ensure immediate response from upstreams.
    • BTo disable connection pooling.
    • CTo prevent indefinite waiting on slow upstreams.
    • DTo allow retries without limits.
  7. 7.A developer sets a 5-second read timeout and a 2-second connect timeout. What does this configuration imply?

    • AThe client will only retry after 7 seconds.
    • BThe client will wait 5 seconds for a connection and 2 seconds for data.
    • CThe client will wait up to 2 seconds for a connection and 5 seconds for data.
    • DThe client will retry after 5 seconds if a connection isn't established.