Symfony

HTTP Client

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

18 питань зі співбесід·
Mid-Level
1

Which Symfony component allows making HTTP requests to external services?

Відповідь

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?

Відповідь

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?

Відповідь

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 питань зі співбесід

Опануй Symfony для наступної співбесіди

Отримай доступ до всіх питань, flashcards, технічних тестів, вправ code review та симуляторів співбесід.

Почни безкоштовно