Struct RequestBuilder

Source
pub struct RequestBuilder { /* private fields */ }
Expand description

A builder for non-streaming outgoing HTTP requests. You can obtain a RequestBuilder from the Request::builder() method, or from method-specific helpers such as Request::get() or Request::post().

§Examples

Use a method helper to build an outgoing POST request:

use spin_sdk::http::{Request, Response};

let request = Request::post("https://example.com", "it's a-me, Spin")
    .header("content-type", "text/plain")
    .build();
let response: Response = spin_sdk::http::send(request).await?;

Build and send an outgoing request using the RequestBuilder.

use spin_sdk::http::{Method, Request, Response};

let request = Request::builder()
    .uri("https://example.com/message/motivational")
    .method(Method::Put)
    .header("content-type", "text/plain")
    .body("the capybaras of creativity fly higher than the bluebirds of banality")
    .build();
let response: Response = spin_sdk::http::send(request).await?;

Implementations§

Source§

impl RequestBuilder

Source

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

Create a new RequestBuilder

Source

pub fn method(&mut self, method: Method) -> &mut Self

Set the method

Source

pub fn uri(&mut self, uri: impl Into<String>) -> &mut Self

Set the uri

Source

pub fn headers(&mut self, headers: impl IntoHeaders) -> &mut Self

Set the headers

Source

pub fn header( &mut self, key: impl Into<String>, value: impl Into<String>, ) -> &mut Self

Set a header

Source

pub fn body(&mut self, body: impl IntoBody) -> &mut Self

Set the body

Source

pub fn build(&mut self) -> Request

Build the Request

Trait Implementations§

Source§

impl TryIntoOutgoingRequest for RequestBuilder

Source§

type Error = Error

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

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

Source§

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

Source§

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.