Struct esp32_simple::http::Client

source ·
pub struct Client<'a> { /* private fields */ }
Expand description

Represents an HTTP client that interacts with a server over Wi-Fi.

This struct provides methods to send HTTP requests, such as POST requests, using the ESP-IDF framework. It owns an active Wi-Fi connection for the duration of its lifetime.

Implementations§

source§

impl<'a> Client<'a>

source

pub fn new(wifi: Connection<'a>) -> Result<Self>

Creates a new Client instance with the given Wi-Fi connection.

§Arguments
  • wifi - An active Wi-Fi connection.
§Returns

A new Client ready to send HTTP requests.

§Errors

Returns an error if the HTTP client cannot be initialized.

source

pub fn post(&mut self, url: &str, payload: Option<&[u8]>) -> Result<u16>

Sends a POST request to the specified URL with an optional payload.

§Arguments
  • url - The URL to send the POST request to.
  • payload - An optional byte slice containing the payload to send.
§Returns

The HTTP status code of the response.

§Errors

Returns an error if the Wi-Fi is not connected, the request fails, or the response status is not in the success range.

Auto Trait Implementations§

§

impl<'a> !Freeze for Client<'a>

§

impl<'a> !RefUnwindSafe for Client<'a>

§

impl<'a> !Send for Client<'a>

§

impl<'a> !Sync for Client<'a>

§

impl<'a> Unpin for Client<'a>

§

impl<'a> !UnwindSafe for Client<'a>

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

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

Performs the conversion.