Expand description
Browser-agnostic HTTP/HTTPS fetching library.
Two APIs are available depending on how much control you need:
simple_get— one-shot GET, no setup required.Fetcher— priority-scheduled fetcher with request coalescing, per-origin concurrency limits, and fan-out to multiple subscribers.
For the full scheduler, implement FetcherContext to receive lifecycle callbacks,
or use NullContext if you don’t need any:
use std::sync::Arc;
use gosub_sonar::{FetchRequest, Fetcher, FetcherConfig, NullContext};
use http::Method;
use tokio_util::sync::CancellationToken;
use url::Url;
let fetcher = Arc::new(Fetcher::new(FetcherConfig::default(), Arc::new(NullContext))?);
let shutdown = CancellationToken::new();
tokio::spawn({
let f = fetcher.clone();
let cancel = shutdown.clone();
async move { f.run(cancel).await }
});
let req = FetchRequest::builder(Method::GET, Url::parse("https://example.org")?).build();
let result = fetcher.fetch(req).await;The most common types are re-exported at the crate root; the full API remains
available under net.
§Examples
Runnable examples are in the examples/ directory:
simple_fetch— one-shot GET usingsimple_getfetcher— minimalFetchersetup with a no-op contextfetcher_harness— self-contained harness covering concurrency, coalescing, priority, cancellation, and errors
Re-exports§
pub use net::fetcher::Fetcher;pub use net::fetcher::FetcherConfig;pub use net::fetcher_context::FetcherContext;pub use net::fetcher_context::NullContext;pub use net::null_emitter::NullEmitter;pub use net::observer::NetObserver;pub use net::request_ref::RequestReference;pub use net::simple::simple_get;pub use net::simple::sync_fetch;pub use net::simple::sync_get;pub use net::types::FetchHandle;pub use net::types::FetchKeyData;pub use net::types::FetchRequest;pub use net::types::FetchRequestBuilder;pub use net::types::FetchResult;pub use net::types::FetchResultMeta;pub use net::types::Initiator;pub use net::types::NetError;pub use net::types::Priority;pub use net::types::RequestBody;pub use net::types::ResourceKind;pub use types::PeekBuf;pub use types::RequestId;