PSR standards · Question 9 of 12
A service calls an external API with the TYPO3 RequestFactory: $this->requestFactory->request($url, 'GET', ['timeout' => 5]). Which statements are true?
2 answers are correct. Medium
Show answer
Answer
- B If the API responds with 404 or 500, Guzzle throws an exception by default that has to be caught
- D The result is a PSR-7 response, and the content is read e.g. with (string)$response->getBody()
Explanation
request() passes the request to a Guzzle client that is preconfigured with the settings from $GLOBALS['TYPO3_CONF_VARS']['HTTP'], such as proxy and headers. Options in the third parameter add to or override them for this call. Globally, timeout is 0, i.e. unlimited, so a custom limit is worthwhile. Since http_errors stays enabled, status codes from 400 lead to a RequestException.