requests & httpx — Calling APIs — Concept Check
Questions on requests & httpx — Calling APIs. requests is the de-facto HTTP client: get/post with params and JSON, status checks with raise_for_status, timeouts ALWAYS, and Sessions for connection reuse.
Questions in this quiz
8 questions on requests & httpx — Calling APIs — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.A developer needs to make multiple GET requests to an API with shared headers and connection pooling. What should they use?
- AUse a requests.Session for connection reuse
- BSet timeout=0 for infinite wait
- CUse httpx.AsyncClient for all requests
- DMake individual requests without a session
2.When making an API call with requests, what is the consequence of omitting the timeout parameter?
- AThe request may hang indefinitely
- BThe request will use a default 5-second timeout
- CThe request will automatically retry
- DThe request will fail immediately
3.A service is experiencing slow response times. The developer notices high status codes in the logs. What might be happening?
- AThe service is returning 4xx/5xx errors
- BThe service is using a fast connection
- CThe service is returning 2xx success codes
- DThe service is not using raise_for_status()
4.A developer uses requests.post with json=payload but receives a 415 Unsupported Media Type error. What is likely wrong?
- AThe server does not accept JSON format
- BThe payload is missing required fields
- CThe timeout value is too low
- DThe URL is incorrect
5.What is the primary advantage of using httpx over requests in a FastAPI application?
- Ahttpx supports async operations
- Bhttpx does not require timeouts
- Chttpx automatically retries on failure
- Dhttpx has better error handling
6.A developer uses raise_for_status() in their requests. What benefit does this provide?
- AEnsures all requests are successful
- BConverts all responses to JSON
- CRetries requests on failure
- DAutomatically raises exceptions for 4xx/5xx responses
7.Why is it important to handle exceptions like requests.Timeout separately in API calls?
- ATo ensure all exceptions are logged
- BTo provide specific error messages for different failure modes
- CTo automatically retry failed requests
- DTo ignore errors and continue execution
8.A developer sets a Retry policy with status_forcelist=[502, 503, 504]. What does this configuration do?
- AAutomatically converts responses to JSON
- BRetries requests on specified HTTP status codes
- CIgnores specified HTTP status codes
- DSets a timeout for each request