Symfony

HTTP Client

HttpClient service, requests, responses, scoped clients, authentication, retry strategies

18 interview questionsยท
Mid-Level
1

Which Symfony component allows making HTTP requests to external services?

Answer

Symfony's HttpClient component provides a modern and performant interface for making HTTP requests. It supports HTTP/2, asynchronous requests, streaming and integrates seamlessly with Symfony's service system via autowiring.

2

Which interface should be injected to use the HTTP client in a Symfony service?

Answer

The HttpClientInterface is the standard contract for injecting the HTTP client via autowiring. This approach decouples code from the concrete implementation and facilitates testing by allowing easy mocking of the client.

3

Which HttpClient method performs an HTTP request and returns a ResponseInterface object?

Answer

The request() method is the main HttpClient method. It accepts the HTTP method, URL and an options array. It returns a ResponseInterface object representing the response lazily, meaning the request is only executed when accessing the content.

4

How to retrieve the JSON content of an HTTP response as a PHP array?

5

Which option allows sending a JSON body in a POST request with HttpClient?

+15 interview questions

Master Symfony for your next interview

Access all questions, flashcards, technical tests, code review exercises and interview simulators.

Start for free