Interface HttpClientProvider
HttpClientProvider enables HTTP endpoints and other components to make outbound HTTP calls to other services, both within the same Akka project and to external services on the internet.
Service-to-Service Communication: When calling other Akka services deployed in the same project, use the service name without protocol or domain. The runtime handles routing, encryption, and authentication automatically.
External Service Communication: For external services, provide full URLs with
http:// or https:// protocols. These calls go over the public internet and
require appropriate authentication.
Usage in Endpoints: Inject HttpClientProvider into endpoint constructors to access HTTP client functionality. The provider creates configured HTTP clients for specific services or URLs.
Security: Service-to-service calls within the same project are automatically secured with mutual TLS and service identity verification. External calls require manual authentication setup.
Not for user extension, instances provided by the SDK through dependency injection.
-
Method Summary
Modifier and TypeMethodDescriptionforPlatformService(String platformService) Returns a provider for HTTP clients to services that belong to a platform service enabled in this project.httpClientFor(String serviceName) Returns aHttpClientto interact with the specified HTTP service.
-
Method Details
-
httpClientFor
Returns aHttpClientto interact with the specified HTTP service.If the serviceName is a service name without protocol or domain the client will be configured to connect to another service deployed with that name on the same Akka project. For a service that is part of a platform service, it connects to a service with that name in the same platform service. The runtime will take care of routing requests to the service and keeping the data safe by encrypting the connection between services and identifying the client as coming from this service.
If it is a full dns name prefixed with "http://" or "https://" it will connect to services available on the public internet.
-
forPlatformService
Returns a provider for HTTP clients to services that belong to a platform service enabled in this project. A service name passed tohttpClientFor(String)on the returned provider is resolved among the services of the platform service instead of the services of this project. The runtime routes and encrypts the calls the same way as calls to services in this project.The returned provider only accepts a bare service name, and throws
IllegalArgumentExceptionfor a host name or a URL.The platform service identifies the caller as a service of the project that the platform service is enabled in. Only
@Acl.Matcherrules with scopeAcl.Scope.PARENT_PROJECTin the platform service match such a caller. The platform service ignores the identity of the calling component.In dev mode and in the test kit, the service is looked up by name only, the same way as a service in this project. A mock registered in the test kit for a service name also applies to a service of that name in a platform service.
Calling a service in a platform service fails when the deployment has no project id, for example in a standalone deployment. A service that is part of a platform service can only call services in its own platform service. Passing the own platform service resolves names the same way as this provider.
- Parameters:
platformService- the name of the platform service, for examplemy-platform-service- Throws:
IllegalArgumentException- if the name is not a lowercase DNS label of at most 26 characters, if the name is the reserved namesvc, or if this service is part of another platform service
-