pub struct Client(pub Client);
๐Deprecated: use
stac
instead of stac-async
, which is deprecated and will receive no further updatesExpand description
A thin wrapper around reqwest::Client.
Tuple Fieldsยง
ยง0: Client
๐Deprecated: use
stac
instead of stac-async
, which is deprecated and will receive no further updatesImplementationsยง
Sourceยงimpl Client
impl Client
Sourcepub fn new() -> Client
๐Deprecated: use stac
instead of stac-async
, which is deprecated and will receive no further updates
pub fn new() -> Client
stac
instead of stac-async
, which is deprecated and will receive no further updatesCreates 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,
๐Deprecated: use stac
instead of stac-async
, which is deprecated and will receive no further updates
pub async fn get<V>(&self, url: impl IntoUrl) -> Result<Option<V>, Error>where
V: DeserializeOwned + Href,
stac
instead of stac-async
, which is deprecated and will receive no further updatesGets 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,
๐Deprecated: use stac
instead of stac-async
, which is deprecated and will receive no further updates
pub async fn post<S, R>(
&self,
url: impl IntoUrl,
data: &S,
) -> Result<Option<R>, Error>where
S: Serialize + 'static,
R: DeserializeOwned,
stac
instead of stac-async
, which is deprecated and will receive no further updatesPosts 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,
๐Deprecated: use stac
instead of stac-async
, which is deprecated and will receive no further updates
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,
stac
instead of stac-async
, which is deprecated and will receive no further updatesSends 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,
๐Deprecated: use stac
instead of stac-async
, which is deprecated and will receive no further updates
pub async fn request_from_link<R>(&self, link: Link) -> Result<Option<R>, Error>where
R: DeserializeOwned,
stac
instead of stac-async
, which is deprecated and will receive no further updatesBuilds 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