konradmichalik / typo3-outbound
Outbound - Declarative API clients for TYPO3: describe external APIs as PHP interfaces with attributes, with retries, caching, rate limits, format profiles and safe defaults.
Package info
github.com/konradmichalik/typo3-outbound
Type:typo3-cms-extension
pkg:composer/konradmichalik/typo3-outbound
Requires
- php: ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0
- ext-mbstring: *
- ext-tokenizer: *
- cuyz/valinor: ^2.7
- psr/http-message: ^1.0 || ^2.0
- psr/http-server-handler: ^1.0.2
- psr/http-server-middleware: ^1.0.2
- psr/log: ^2.0 || ^3.0
- symfony/console: ^7.4
- symfony/dependency-injection: ^7.4
- symfony/http-client: ^7.4
- symfony/http-client-contracts: ^3.5
- symfony/http-foundation: ^7.4
- symfony/mime: ^7.4
- symfony/rate-limiter: ^7.4.23
- symfony/yaml: ^7.4
- typo3/cms-core: ^13.4 || ^14.0
Requires (Dev)
- eliashaeussler/typo3-vendor-bundler: ^4.1.2
- eliashaeussler/version-bumper: ^4.1.3
- phpunit/phpunit: ^11.5 || ^12.0
- psr/container: ^2.0
- symfony/config: ^7.4
- typo3/cms-base-distribution: ^13.4 || ^14.0
- typo3/cms-extbase: ^13.4 || ^14.0
- typo3/cms-fluid: ^13.4 || ^14.0
- typo3/cms-frontend: ^13.4 || ^14.0
- typo3/testing-framework: ^8.2 || ^9.0
Suggests
- phpunit/phpunit: Required for OutboundTestTrait.
Provides
None
Conflicts
None
Replaces
None
README
TYPO3 extension typo3_outbound
This extension lets you describe external APIs as PHP interfaces with attributes and generates the implementation. Your code calls methods and receives typed objects, without HTTP code of its own.
Note
The goal is to replace the hand-written service wrapper per API: you declare what an API offers, and timeouts, retries, caching and security come as safe defaults.
Outbound as in outgoing requests: your site calls the API.
Warning
This extension is at an early stage. Attributes and APIs may still change before 1.0, so try it in a pilot before relying on it in production.
✨ Features
- Less code per API: one interface method per endpoint and typed DTOs instead of request classes and HTTP plumbing
- Fast pages: responses are cached and tied to the page cache, and a write can clear the pages showing the changed data
- Pages keep rendering when an API fails: short timeouts, safe retries, a circuit breaker and, if you allow it, stale data to bridge an outage
- Secure by default: HTTPS only, allowed hosts, private networks blocked, secrets from the environment and redacted logs
- Made for TYPO3: per-site credentials from site settings, the caching framework and console commands to inspect and call every endpoint
- Quick start from OpenAPI: interfaces and DTOs generated from an OpenAPI document or a sample response
- Tests without network: mocks by endpoint instead of URL, in unit and functional tests
🔥 Installation
Requirements
- TYPO3 >= 13.4
- PHP 8.2+
- Symfony components 7.4
Composer
composer require konradmichalik/typo3-outbound
TER
Download the zip file from TYPO3 extension repository (TER).
🚀 Quick start
Declare the API as an interface carrying #[Connection] and annotate a method with an HTTP verb:
use KonradMichalik\Typo3Outbound\Attribute as Outbound; #[Outbound\Connection(baseUri: 'https://api.weather.example.com')] interface WeatherApi { /** @return array{city: string, temperature: float} */ #[Outbound\Get('/forecast/{city}')] public function forecast(string $city): array; }
Inject the interface wherever you need it and call the method:
final readonly class ForecastService { public function __construct(private WeatherApi $weather) {} public function temperatureIn(string $city): float { return $this->weather->forecast($city)['temperature']; } }
That's it: temperatureIn('Dresden') sends GET https://api.weather.example.com/forecast/Dresden, checks the JSON response against the declared shape and reads its temperature. For larger responses, return a DTO class instead of an array shape. Every interface with #[Connection] or #[Resource] that your Configuration/Services.yaml resource covers becomes a service.
Everything else is opt-in on top of that. A larger API splits into resources, takes its base URI and secret from the site configuration, maps responses to DTOs, retries, caches and maps a 404 to null, all declared with attributes:
use KonradMichalik\Typo3Outbound\Value\{Secret, SiteSetting}; #[Outbound\Connection(baseUri: new SiteSetting('crm.baseUri'), allowedHosts: ['crm.example.com'])] #[Outbound\Auth\Bearer(token: new Secret('crm.token'))] #[Outbound\Retry(maxRetries: 2)] interface CrmApi {} #[Outbound\Resource('/contacts')] interface ContactsApi extends CrmApi { #[Outbound\Get('/{id}')] #[Outbound\Cache(lifetime: 600, tags: ['crm_contact_{id}'], staleOnError: 3600)] #[Outbound\OnStatus(404, returns: null)] public function find(int $id): ?ContactDto; }
See Defining endpoints for connections, resources, parameters and return types, and Features for every opt-in attribute.
📚 Documentation
Full documentation lives in docs/:
| Part | What's inside |
|---|---|
| Defining endpoints | Connections, resources, endpoints, parameters, return types, DTOs and naming: the only part you need to call an API |
| Features | Caching, retries and timeouts, rate limits, circuit breaker, pagination, formats, deferred calls and API conventions |
| Operating it | Installation, configuration, caches, the console commands and testing with mocks |
| Background | Architecture, security model, performance figures and the comparison with Saloon |
| Migrating a wrapper | How to replace an existing service wrapper step by step |
Tip
Offering endpoints instead of consuming them?
typo3-routing declares frontend endpoints with a #[Route] attribute on a controller method.
🧑💻 Contributing
Please have a look at CONTRIBUTING.md.
⭐ License
This project is licensed under GNU General Public License 2.0 (or later).