Struct stac_async::ApiClient
source · pub struct ApiClient { /* private fields */ }Expand description
A client for interacting with STAC APIs.
Implementations§
source§impl ApiClient
impl ApiClient
sourcepub fn new(url: &str) -> Result<ApiClient>
pub fn new(url: &str) -> Result<ApiClient>
Creates a new API client.
§Examples
let client = ApiClient::new("https://planetarycomputer.microsoft.com/api/stac/v1").unwrap();sourcepub fn with_client(client: Client, url: &str) -> Result<ApiClient>
pub fn with_client(client: Client, url: &str) -> Result<ApiClient>
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_async::{Client, ApiClient};
let client = Client::new();
let api_client = ApiClient::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 = ApiClient::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;
use stac_async::ApiClient;
use futures_util::stream::StreamExt;
let client = ApiClient::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;
use stac_async::ApiClient;
use futures_util::stream::StreamExt;
let client = ApiClient::new("https://planetarycomputer.microsoft.com/api/stac/v1").unwrap();
let mut search = Search { collections: Some(vec!["sentinel-2-l2a".to_string()]), ..Default::default() };
search.items.limit = Some(1);
let items: Vec<_> = client
.search(search)
.await
.unwrap()
.map(|result| result.unwrap())
.collect()
.await;
assert_eq!(items.len(), 1);Trait Implementations§
Auto Trait Implementations§
impl Freeze for ApiClient
impl !RefUnwindSafe for ApiClient
impl Send for ApiClient
impl Sync for ApiClient
impl Unpin for ApiClient
impl !UnwindSafe for ApiClient
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