pub struct ServiceRequestBuilder<S: ServiceType> { /* private fields */ }
Expand description

A request builder for a service.

Implementations§

source§

impl<S> ServiceRequestBuilder<S>where S: ServiceType,

source

pub fn client(&self) -> &AuthenticatedClient

Get a reference to the client.

source

pub fn body<T: Into<Body>>(self, body: T) -> ServiceRequestBuilder<S>

Add a body to the request.

source

pub fn header<K, V>(self, key: K, value: V) -> ServiceRequestBuilder<S>where HeaderName: TryFrom<K>, <HeaderName as TryFrom<K>>::Error: Into<HttpError>, HeaderValue: TryFrom<V>, <HeaderValue as TryFrom<V>>::Error: Into<HttpError>,

Add a header to the request.

source

pub fn headers(self, headers: HeaderMap) -> ServiceRequestBuilder<S>

Add headers to a request.

source

pub fn json<T: Serialize + ?Sized>(self, json: &T) -> ServiceRequestBuilder<S>

Add a JSON body to the request.

source

pub fn query<T: Serialize + ?Sized>(self, query: &T) -> ServiceRequestBuilder<S>

Send a query with the request.

Query objects can be used for type-safe querying without creating a potentially large structure with all possible filters:

use std::borrow::Cow;

#[derive(Debug)]
enum NodeFilter {
    Associated(bool),
    ResourceClass(String),
    Limit(usize),
    // ... a lot of items here ...
}

impl osauth::QueryItem for NodeFilter {
    fn query_item(&self) -> Result<(&str, Cow<str>), osauth::Error> {
        Ok(match self {
            NodeFilter::Associated(a) => ("associated", a.to_string().into()),
            NodeFilter::ResourceClass(s) => ("resource_class", s.into()),
            NodeFilter::Limit(l) => ("limit", l.to_string().into()),
        })
    }
}

let session = osauth::Session::from_env().await?;
let query = osauth::Query::default()
    .with(NodeFilter::Associated(true))
    .with(NodeFilter::ResourceClass("x1.large".into()))
    .with(NodeFilter::Limit(100));
let request = session
    .get(osauth::services::BAREMETAL, &["nodes"])
    .query(&query);
source

pub fn timeout(self, timeout: Duration) -> ServiceRequestBuilder<S>

Override the timeout for the request.

source

pub async fn fetch<T>(self) -> Result<T, Error>where T: DeserializeOwned + Send, S: Send,

Send the request and receive JSON in response.

source

pub async fn send(self) -> Result<Response, Error>where S: Send,

Send the request and check for errors.

source

pub async fn send_unchecked(self) -> Result<Response, Error>where S: Send,

Send the request without checking for HTTP and OpenStack errors.

source§

impl<S> ServiceRequestBuilder<S>where S: VersionedService,

source

pub fn api_version<A: Into<ApiVersion>>( self, version: A ) -> ServiceRequestBuilder<S>

Add an API version to this request.

source

pub fn set_api_version<A: Into<ApiVersion>>(&mut self, version: A)

Set the API version on the request.

source§

impl<S> ServiceRequestBuilder<S>where S: ServiceType + Clone,

source

pub async fn fetch_paginated<T>( self, limit: Option<usize>, starting_with: Option<<T as PaginatedResource>::Id> ) -> impl Stream<Item = Result<T, Error>>where S: Send + Sync, T: PaginatedResource + Unpin, <T as PaginatedResource>::Root: Into<Vec<T>> + Send,

Send the request and receive JSON in response with pagination.

Note that the actual requests will happen only on iteration over the results.

To use this feature, you need to implement PaginatedResource for your resource class. This can be done with derive:

use futures::pin_mut;
use futures::stream::TryStreamExt;
use serde::Deserialize;
use osauth::PaginatedResource;

#[derive(Debug, Deserialize, PaginatedResource)]
#[collection_name = "servers"]
pub struct Server {
    #[resource_id]
    pub id: String,
    pub name: String,
}

let session = osauth::Session::from_env().await?;

let servers = session
    .get(osauth::services::COMPUTE, &["servers"])
    .fetch_paginated::<Server>(None, None)
    .await;

pin_mut!(servers);
while let Some(srv) = servers.try_next().await? {
    println!("ID = {}, Name = {}", srv.id, srv.name);
}

See PaginatedResource for more information on how to implement it.

Panics

Will panic during iteration if the request builder has a streaming body.

source

pub fn try_clone(&self) -> Option<ServiceRequestBuilder<S>>

Attempt to clone this request builder.

Trait Implementations§

source§

impl<S: Debug + ServiceType> Debug for ServiceRequestBuilder<S>

source§

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

Formats the value using the given formatter. Read more
source§

impl<S> From<ServiceRequestBuilder<S>> for RequestBuilderwhere S: ServiceType,

source§

fn from(value: ServiceRequestBuilder<S>) -> RequestBuilder

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<S> !RefUnwindSafe for ServiceRequestBuilder<S>

§

impl<S> Send for ServiceRequestBuilder<S>where S: Send,

§

impl<S> Sync for ServiceRequestBuilder<S>where S: Sync,

§

impl<S> Unpin for ServiceRequestBuilder<S>where S: Unpin,

§

impl<S> !UnwindSafe for ServiceRequestBuilder<S>

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.

§

impl<T> Instrument for T

§

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

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

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, 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.
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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