pub struct Client { /* private fields */ }
Available on crate feature
client
only.Expand description
A client for interacting with STAC APIs.
Implementations§
Source§impl Client
impl Client
Sourcepub fn new(url: &str) -> Result<Client>
pub fn new(url: &str) -> Result<Client>
Creates a new API client.
§Examples
let client = Client::new("https://planetarycomputer.microsoft.com/api/stac/v1").unwrap();
Sourcepub fn with_client(client: Client, url: &str) -> Result<Client>
pub fn with_client(client: Client, url: &str) -> Result<Client>
Creates a new API client with the given Client.
Useful if you want to customize the behavior of the underlying Client
,
as documented in Client::new.
§Examples
use stac_api::Client;
let client = reqwest::Client::new();
let client = Client::with_client(client, "https://earth-search.aws.element84.com/v1/").unwrap();
Sourcepub async fn collection(&self, id: &str) -> Result<Option<Collection>>
pub async fn collection(&self, id: &str) -> Result<Option<Collection>>
Returns a single collection.
§Examples
let client = Client::new("https://planetarycomputer.microsoft.com/api/stac/v1").unwrap();
let collection = client.collection("sentinel-2-l2a").await.unwrap().unwrap();
Sourcepub async fn items(
&self,
id: &str,
items: impl Into<Option<Items>>,
) -> Result<impl Stream<Item = Result<Item>>>
pub async fn items( &self, id: &str, items: impl Into<Option<Items>>, ) -> Result<impl Stream<Item = Result<Item>>>
Returns a stream of items belonging to a collection, using the items endpoint.
The items
argument can be used to filter, sort, and otherwise
configure the request.
§Examples
use stac_api::{Items, Client};
use futures::StreamExt;
let client = Client::new("https://planetarycomputer.microsoft.com/api/stac/v1").unwrap();
let items = Items {
limit: Some(1),
..Default::default()
};
let items: Vec<_> = client
.items("sentinel-2-l2a", items)
.await
.unwrap()
.map(|result| result.unwrap())
.collect()
.await;
assert_eq!(items.len(), 1);
Sourcepub async fn search(
&self,
search: Search,
) -> Result<impl Stream<Item = Result<Item>>>
pub async fn search( &self, search: Search, ) -> Result<impl Stream<Item = Result<Item>>>
Searches an API, returning a stream of items.
§Examples
use stac_api::{Search, Client};
use futures::StreamExt;
let client = Client::new("https://planetarycomputer.microsoft.com/api/stac/v1").unwrap();
let mut search = Search { collections: Some(vec!["sentinel-2-l2a".to_string()]), ..Default::default() };
let items: Vec<_> = client
.search(search)
.await
.unwrap()
.take(1)
.map(|result| result.unwrap())
.collect()
.await;
assert_eq!(items.len(), 1);
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Client
impl !RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl !UnwindSafe for Client
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more