Struct stac_async::Client

source ·
pub struct Client(pub Client);
Expand description

A thin wrapper around reqwest::Client.

Tuple Fields§

§0: Client

Implementations§

source§

impl Client

source

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);
source

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();
source

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 search = Search { limit: Some(1), ..Default::default() };
let items: stac_api::ItemCollection = client.post(href, &search).await.unwrap().unwrap();
source

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();

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§

source§

impl Clone for Client

source§

fn clone(&self) -> Client

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Client

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

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> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more