API-Anfragen typsicher und resilient
Wer externe APIs in PHP mit cURL oder Guzzle anspricht, baut oft fragile Integrationen ohne Retry-Logik, ohne sauberes Mocking in Tests und ohne Typsicherheit. Symfony HttpClient liefert all das als Teil des Frameworks — mit Scoped Clients, automatischen Retries, asynchroner Concurrency und einem MockHttpClient für vollständig isolierte Unit-Tests.
Inhaltsverzeichnis
- 1. Warum Symfony HttpClient statt Guzzle oder cURL
- 2. Installation und Grundkonfiguration
- 3. Scoped Clients: API-Konfiguration gebündelt
- 4. Typsichere API-Wrapper mit DTOs
- 5. Retry-Logik und Fehlerbehandlung
- 6. Asynchrone Anfragen und Concurrency
- 7. Mocking mit MockHttpClient in Tests
- 8. Streaming großer Antworten
- 9. HttpClient-Implementierungen im Vergleich
- 10. Zusammenfassung
- 11. FAQ