roas-http-fetcher
HTTP/HTTPS ResourceFetcher and
AsyncResourceFetcher for the
roas OpenAPI loader.
Built on reqwest with rustls-tls. A single generic Fetcher<C> underlies two type aliases:
HttpFetcher(=Fetcher<reqwest::blocking::Client>) — implementsResourceFetcherforLoader::register_fetcher.AsyncHttpFetcher(=Fetcher<reqwest::Client>) — implementsAsyncResourceFetcherforLoader::register_async_fetcher. A tokio runtime must be active when the returned future is awaited.
Both forms are Clone so a single fetcher can be registered for both http:// and https:// prefixes on the same Loader, sharing one underlying connection pool. Schemes other than http / https are rejected with LoaderError::UnsupportedFetcherUri. The default constructor builds a client with a 30-second request timeout; try_new() is the fallible variant that surfaces TLS / IO environment failures from reqwest::ClientBuilder.
Features
- (default) JSON response bodies are parsed with
serde_json. yaml— also accept YAML response bodies. The fetcher sniffsContent-Typefirst (application/yaml,application/x-yaml,text/yaml, etc.) and falls back to the URL path extension (.yaml/.yml). Pulls inserde_yaml_ng.
[]
= { = "0.1", = ["yaml"] }
Usage
cargo add roas-http-fetcher
use Loader;
use HttpFetcher;
let mut loader = new;
let http = new;
loader.register_fetcher;
loader.register_fetcher;
For async loaders use AsyncHttpFetcher with register_async_fetcher instead — same shape:
use Loader;
use AsyncHttpFetcher;
let mut loader = new;
let http = new;
loader.register_async_fetcher;
loader.register_async_fetcher;
A non-2xx HTTP response, transport failure, or unreadable body is surfaced through
LoaderError::Fetch with a
HttpFetchError source.
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.