Struct stac_async::Client
source · pub struct Client(pub Client);Expand description
A thin wrapper around reqwest::Client.
Tuple Fields§
§0: ClientImplementations§
source§impl Client
impl Client
sourcepub fn new() -> Client
pub fn new() -> Client
Creates a new client.
§Examples
let client = stac_async::Client::new();§Custom client
You can construct the client directly using a pre-built reqwest::Client, e.g. to do authorization:
use reqwest::header;
let mut headers = header::HeaderMap::new();
let mut auth_value = header::HeaderValue::from_static("secret");
auth_value.set_sensitive(true);
headers.insert(header::AUTHORIZATION, auth_value);
let client = reqwest::Client::builder().default_headers(headers).build().unwrap();
let client = stac_async::Client(client);sourcepub async fn get<V>(&self, url: impl IntoUrl) -> Result<Option<V>, Error>where
V: DeserializeOwned + Href,
pub async fn get<V>(&self, url: impl IntoUrl) -> Result<Option<V>, Error>where
V: DeserializeOwned + Href,
Gets a STAC value from a url.
Also sets that Values href. Returns Ok(None) if a 404 is returned from the server.
§Examples
let client = stac_async::Client::new();
let href = "https://raw.githubusercontent.com/radiantearth/stac-spec/v1.0.0/examples/simple-item.json";
let item: stac::Item = client.get(href).await.unwrap().unwrap();sourcepub async fn post<S, R>(
&self,
url: impl IntoUrl,
data: &S,
) -> Result<Option<R>, Error>where
S: Serialize + 'static,
R: DeserializeOwned,
pub async fn post<S, R>(
&self,
url: impl IntoUrl,
data: &S,
) -> Result<Option<R>, Error>where
S: Serialize + 'static,
R: DeserializeOwned,
Posts data to a url.
§Examples
use stac_api::Search;
let client = stac_async::Client::new();
let href = "https://planetarycomputer.microsoft.com/api/stac/v1/search";
let mut search = Search::default();
search.items.limit = Some(1);
let items: stac_api::ItemCollection = client.post(href, &search).await.unwrap().unwrap();sourcepub async fn request<S, R>(
&self,
method: Method,
url: impl IntoUrl,
params: impl Into<Option<&S>>,
headers: impl Into<Option<HeaderMap>>,
) -> Result<Option<R>, Error>where
S: Serialize + 'static,
R: DeserializeOwned,
pub async fn request<S, R>(
&self,
method: Method,
url: impl IntoUrl,
params: impl Into<Option<&S>>,
headers: impl Into<Option<HeaderMap>>,
) -> Result<Option<R>, Error>where
S: Serialize + 'static,
R: DeserializeOwned,
Sends a request to a url.
§Examples
use stac::Item;
use reqwest::Method;
let client = stac_async::Client::new();
let href = "https://raw.githubusercontent.com/radiantearth/stac-spec/v1.0.0/examples/simple-item.json";
let item = client.request::<(), Item>(Method::GET, href, None, None).await.unwrap().unwrap();sourcepub async fn request_from_link<R>(&self, link: Link) -> Result<Option<R>, Error>where
R: DeserializeOwned,
pub async fn request_from_link<R>(&self, link: Link) -> Result<Option<R>, Error>where
R: DeserializeOwned,
Builds and sends a request, as defined in a link.
Used mostly for “next” links in pagination.
§Examples
use stac::Link;
let link = Link::new("http://stac-async-rs.test/search?foo=bar", "next");
let client = stac_async::Client::new();
let page: stac_api::ItemCollection = client.request_from_link(link).await.unwrap().unwrap();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§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit)