-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Custom HTTP Clients
Azure SDKs for Java offers the capability to plug-in your own custom networking layer to allow for handling of specialized scenarios or when you don't want to use Netty or OkHttp. Providing a custom HttpClient
requires a few interfaces/classes to be implemented along with registering your implementation with Java's service provider interface.
The following interfaces and abstract classes will need to be implemented in your custom HTTP client.
- HttpClient handles sending request and receiving responses.
- HttpResponse contains response information and APIs to interact with it.
-
HttpClientProvider handles creating instances of the
HttpClient
agnostic to the underlying implementation.
A specific version of Azure Core will need to be targeted when implementing a custom HTTP client. This version should be based on which version of Azure Core is being used by the other Azure SDK client libraries your application is depending on, for example if you have a dependency on Azure Storage Blobs that uses Azure Core 1.2.0 you'll want your custom HTTP client to use that as it's dependency.
Once the custom HTTP client has been implemented it needs to be registered with Java's service provider interface. In the module that contains the custom HTTP client the resource folder will need the following.
src
|
+--main
|
+--java
+--resources
|
+--META-INF.services
|
+--com.azure.core.http.HttpClientProvider
The only contents of com.azure.core.http.HttpClientProvider
file should be the fully qualified name of the class that implements HttpClientProvider
. For example if this class is custom.http.MyHttpClientProvider
the file would only contain custom.http.MyHttpClientProvider
.
This is a high-level example of a custom HTTP client implementation built on top of org.apache.httpcomponents.httpclient
and using Azure Core 1.2.0. This example hasn't be verified for correctness or scalability but serves as a general example of how to roll your own HTTP client.
- Frequently Asked Questions
- Azure Identity Examples
- Configuration
- Performance Tuning
- Android Support
- Unit Testing
- Test Proxy Migration
- Azure Json Migration
- New Checkstyle and Spotbugs pattern migration
- Protocol Methods
- TypeSpec-Java Quickstart
- Getting Started Guidance
- Adding a Module
- Building
- Writing Performance Tests
- Working with AutoRest
- Deprecation
- BOM guidelines
- Release process
- Access helpers