Skip to content

Commit 8280f77

Browse files
authored
Document how to replace some features (Azure#2952)
Resolves Azure#2931
1 parent db797d8 commit 8280f77

File tree

2 files changed

+40
-5
lines changed

2 files changed

+40
-5
lines changed

.vscode/cspell.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
"vcpkg",
8787
"versionid",
8888
"virtualmachine",
89+
"webpki",
8990
"worktree"
9091
],
9192
"dictionaryDefinitions": [

sdk/core/azure_core/README.md

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,11 @@ We guarantee that all client instance methods are thread-safe and independent of
3737

3838
[Client options](#configuring-service-clients-using-clientoptions) |
3939
[Accessing the response](#accessing-http-response-details-using-responset) |
40-
[Handling Errors Results](#handling-errors-results) |
41-
[Consuming Service Methods Returning `Pager<T>`](#consuming-service-methods-returning-pagert)
40+
[Handling errors](#handling-errors) |
41+
[Iterating through pages of resources](#consuming-service-methods-returning-pagert) |
42+
[Waiting on long-running operations](#consuming-service-methods-returning-pollert) |
43+
[Replacing the HTTP client](#replacing-the-http-client) |
44+
[Replacing the async runtime](#replacing-the-async-runtime)
4245

4346
<!-- CLIENT COMMON BAR -->
4447

@@ -49,14 +52,45 @@ We guarantee that all client instance methods are thread-safe and independent of
4952
- `derive`: enable derive macros e.g., `SafeDebug`.
5053
- `hmac_openssl`: enables HMAC signing using `openssl`. If both `hmac_openssl` and `hmac_rust` are enabled, `hmac_openssl` is used.
5154
- `hmac_rust`: enables HMAC signing using rust-native libraries `sha2` and `hmac`. If both `hmac_openssl` and `hmac_rust` are enabled, `hmac_openssl` is used.
52-
- `reqwest` (default): enables and sets `reqwest` as the default `HttpClient`. Enables `reqwest`'s `native-tls` feature.
55+
- `reqwest` (default): enables and sets `reqwest` as the default `HttpClient`.
5356
- `reqwest_deflate` (default): enables deflate compression for `reqwest`.
5457
- `reqwest_gzip` (default): enables gzip compression for `reqwest`.
5558
- `reqwest_native-tls` (default): enables `reqwest`'s `native-tls` feature, which uses schannel on Windows and openssl elsewhere.
5659
- `tokio`: enables and sets `tokio` as the default async runtime.
5760
- `wasm_bindgen`: enables the async runtime for WASM.
5861
- `xml`: enables XML support.
5962

63+
### Enabling dependencies' features
64+
65+
We define features to avoid dependencies which may be unnecessary for some applications or even some client libraries e.g.,
66+
some Azure services do not support the `accept-encoding` request header nor send `content-encoding` back so there's no need to add `reqwest_gzip` by default
67+
for all client libraries. We also want to support developers that want to use additional features of some dependencies like `reqwest`
68+
or even replace some dependencies completely like `reqwest` or `tokio` to use different HTTP clients or async runtimes.
69+
70+
We do not define features to provide parity with all dependencies' features since the [resolver](https://doc.rust-lang.org/cargo/reference/resolver.html)
71+
will unify features e.g., you can add `reqwest`'s `system-proxy` feature without making any changes to Azure SDK dependencies:
72+
73+
```toml
74+
[dependencies]
75+
azure_identity = "1"
76+
azure_security_keyvault_secrets = "1"
77+
reqwest = { version = "0.12.23", features = ["system-proxy"] }
78+
```
79+
80+
Similarly, you can choose to support `reqwest::Client` but use `rustls-tls` with a different TLS provider by disabling our default features
81+
and adding only what you need, such as our `reqwest` feature just to enable the `HttpClient` trait implementation on `reqwest::Client` and
82+
add a dependency on `reqwest` with the feature you want:
83+
84+
```toml
85+
[dependencies]
86+
azure_core = { version = "1", default-features = false, features = ["reqwest"] }
87+
azure_identity = { version = "1", default-features = false }
88+
azure_security_keyvault_secrets = { version = "1", default-features = false }
89+
reqwest = { version = "0.12.23", features = ["rustls-tls-webpki-roots"] }
90+
```
91+
92+
You could even completely replace `reqwest` and provide your own `HttpClient` implementation. See [an example](#other-http-client) below.
93+
6094
## Examples
6195

6296
**NOTE:** Samples in this file apply only to packages that follow [Azure SDK Design Guidelines][guidelines]. Names of such packages typically start with `azure_`.
@@ -143,7 +177,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
143177
}
144178
```
145179

146-
### Handling errors results
180+
### Handling errors
147181

148182
When a service call fails, the returned `Result` will contain an `Error`. The `Error` type provides a status property with an HTTP status code and an error_code property with a service-specific error code.
149183

@@ -424,7 +458,7 @@ let client = SecretClient::new(
424458
.unwrap();
425459
```
426460

427-
#### Other
461+
#### Other HTTP client
428462

429463
If you do not want to take a dependency on [`reqwest`] at all - perhaps because you [want to use a different async runtime](#replacing-the-async-runtime) other than [`tokio`] -
430464
you can implement the `HttpClient` (recommended) or the `Policy` trait yourself.

0 commit comments

Comments
 (0)