Struct spin_sdk::http::Request

source ·
pub struct Request { /* private fields */ }
Expand description

A unified request object that can represent both incoming and outgoing requests.

This should be used in favor of IncomingRequest and OutgoingRequest when there is no need for streaming bodies.

Implementations§

source§

impl Request

source

pub fn new(method: Method, uri: impl Into<String>) -> Self

Creates a new request from a method and uri

source

pub fn builder() -> RequestBuilder

Creates a RequestBuilder

source

pub fn get(uri: impl Into<String>) -> RequestBuilder

Creates a RequestBuilder to GET the given uri

source

pub fn post(uri: impl Into<String>, body: impl IntoBody) -> RequestBuilder

Creates a RequestBuilder to POST the given body to uri

source

pub fn put(uri: impl Into<String>, body: impl IntoBody) -> RequestBuilder

Creates a RequestBuilder to PUT the given body to uri

source

pub fn patch(uri: impl Into<String>, body: impl IntoBody) -> RequestBuilder

Creates a RequestBuilder to PATCH the resource specified by uri

source

pub fn delete(uri: impl Into<String>) -> RequestBuilder

Creates a RequestBuilder to DELETE the resource specified by uri

source

pub fn method(&self) -> &Method

The request method

source

pub fn uri(&self) -> &str

The request uri

source

pub fn path(&self) -> &str

The request uri path

source

pub fn query(&self) -> &str

The request uri query

source

pub fn headers(&self) -> impl Iterator<Item = (&str, &HeaderValue)>

The request headers

source

pub fn header(&self, name: &str) -> Option<&HeaderValue>

Return a header value

Will return None if the header does not exist.

source

pub fn set_header(&mut self, name: impl Into<String>, value: impl Into<String>)

Set a header

source

pub fn body(&self) -> &[u8]

The request body

source

pub fn body_mut(&mut self) -> &mut Vec<u8>

The request body

source

pub fn into_body(self) -> Vec<u8>

Consume this type and return its body

source

pub fn path_and_query(&self) -> Option<&str>

The request path and query combined

Trait Implementations§

source§

impl TryFromIncomingRequest for Request

§

type Error = IncomingRequestError

The error if conversion fails
source§

fn try_from_incoming_request<'async_trait>( request: IncomingRequest ) -> Pin<Box<dyn Future<Output = Result<Self, Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait,

Try to turn the IncomingRequest into the implementing type
source§

impl TryFromRequest for Request

§

type Error = Infallible

The error if the conversion fails
source§

fn try_from_request(req: Request) -> Result<Self, Self::Error>
where Self: Sized,

Try to turn the request into the type
source§

impl TryIntoOutgoingRequest for Request

§

type Error = Infallible

The error if the conversion fails
source§

fn try_into_outgoing_request( self ) -> Result<(OutgoingRequest, Option<Vec<u8>>), Self::Error>

Turn the type into an OutgoingRequest Read more
source§

impl TryIntoRequest for Request

§

type Error = Infallible

The error if the conversion fails
source§

fn try_into_request(self) -> Result<Request, Self::Error>

Turn self into a Request

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where 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, U> Into<U> for T
where 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 T
where 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 T
where 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.