Expand description
§TypeSpec Client Runtime
This is the runtime for TypeSpec-generated clients.
§Features
debug
: enables extra information for developers e.g., emitting all fields instd::fmt::Debug
implementation.decimal
: enables support forrust_decimal::Decimal
type.derive
: enable derive macros e.g.,SafeDebug
.http
(default): enables HTTP support.json
(default): enables JSON support.reqwest
(default): enables and setsreqwest
as the defaultHttpClient
. Enablesreqwest
’snative-tls
feature.reqwest_deflate
(default): enables deflate compression forreqwest
.reqwest_gzip
(default): enables gzip compression forreqwest
.reqwest_native_tls
(default): enablesreqwest
’snative-tls
feature, which uses schannel on Windows and openssl elsewhere.tokio
: enables and setstokio
as the default async runtime.wasm_bindgen
: enables the async runtime for WASM.xml
: enables XML support.
§Troubleshooting
§Logging
To help protected end users from accidental Personally-Identifiable Information (PII) from leaking into logs or traces, models’ default implementation of core::fmt::Debug
formats as non-exhaustive structure tuple e.g.,
#[macro_use]
use typespec_client_core::fmt::SafeDebug;
#[derive(SafeDebug)]
struct Person {
name: String,
}
let p = Person {
name: "Any One".into(),
};
println!("{p:?}");
By default this will print:
Person { .. }
Though not recommended for production, you can enable normal core::fmt::Debug
formatting complete with field names and values by enabling the debug
feature of typespec_client_core
e.g.,
cargo add typespec_client_core -F debug
§Known issues
§Hang when invoking multiple HTTP operations using the default HTTP transport
Some customers have reported hangs when using the default reqwest
HTTP transport.
The issue is tracked in this GitHub issue.
The recommended workaround is to disable connection pooling in a custom reqwest
transport.
If you are encountering this issue, you can construct an HttpClient
which disables HTTP connection pooling
and set that as the transport in any ClientOptions
used to configure your clients:
use std::sync::Arc;
use typespec_client_core::http::{HttpClient, ClientOptions, Transport};
let client = Arc::new(
::reqwest::ClientBuilder::new()
// Note that reqwest does not support `pool_max_idle_per_host` on WASM.
.pool_max_idle_per_host(0)
.build()
.expect("failed to build `reqwest` client"),
);
let options = ClientOptions {
transport: Some(Transport::new(client.clone())),
..Default::default()
};
Note that implementing this workaround can result in a significant performance slowdown depending on your scenario.
§Contributing
See the [CONTRIBUTING.md] for details on building, testing, and contributing to these libraries.
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://opensource.microsoft.com/cla/.
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the [Microsoft Open Source Code of Conduct]. For more information see the [Code of Conduct FAQ] or contact opencode@microsoft.com with any additional questions or comments.
Re-exports§
pub use sleep::sleep;
Modules§
- async_
runtime - Asynchronous task execution utilities.
- base64
- Base64 encoding and decoding functions.
- error
- Client-specific error functions.
- fmt
- Formatting helpers.
- http
http
- Types and functions for building HTTP clients.
- json
json
- JSON serialization functions.
- sleep
- Sleep functions.
- stream
- Asynchronous streams.
- time
- Date and time parsing and formatting functions.
- tracing
http
- Distributed tracing trait definitions
- xml
xml
- XML serialization functions.
Macros§
- request_
header - Creates named value type that can be used to construct requests.
- request_
option - Creates a named value type that can be used as a header or in a query string.
- request_
query - Creates a named value that can be used in a query string.
Structs§
- Bytes
- A cheaply cloneable and sliceable chunk of contiguous memory.
- Error
- An error encountered when communicating with the service.
- Uuid
- A Universally Unique Identifier (UUID).