Skip to main content

RequestWriter

Struct RequestWriter 

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

Sans-IO HTTP request encoder.

Owns a WriteBuf and endpoint configuration. The typestate builder methods serialize HTTP requests directly into the buffer. finish() returns Request<'_> borrowing the assembled bytes.

§Usage

use nexus_web::rest::RequestWriter;

let mut writer = RequestWriter::new("api.binance.com")?;
writer.set_base_path("/api/v3")?;
writer.default_header("X-API-KEY", &key)?;

let req = writer.get("/orders")
    .query("symbol", "BTC-USD")
    .finish()?;

// req.as_bytes() contains the complete HTTP request wire bytes

Implementations§

Source§

impl RequestWriter

Source

pub fn new(host: &str) -> Result<Self, RestError>

Create a new writer for the given host.

Pre-serializes the Host and Connection: keep-alive headers. Default write buffer: 32KB.

§Errors

Returns RestError::CrlfInjection if host contains CR/LF.

Source

pub fn set_write_buffer_capacity(&mut self, capacity: usize)

Set the write buffer capacity. Default: 32KB.

Must be called before any requests are built.

§Panics

Panics if capacity is 0.

Source

pub fn default_header( &mut self, name: &str, value: &str, ) -> Result<(), RestError>

Add a default header sent with every request.

Pre-serializes into wire format. Append-only.

§Errors

Returns RestError::CrlfInjection if name or value contains CR/LF.

Source

pub fn set_base_path(&mut self, path: &str) -> Result<(), RestError>

Set a base path prefix prepended to all request paths.

Trailing slashes are stripped. Request paths should start with /.

§Errors

Returns RestError::CrlfInjection if the path contains CR/LF.

Source

pub fn get(&mut self, path: &str) -> RequestBuilder<'_>

Build a GET request.

Source

pub fn post(&mut self, path: &str) -> RequestBuilder<'_>

Build a POST request.

Source

pub fn put(&mut self, path: &str) -> RequestBuilder<'_>

Build a PUT request.

Source

pub fn delete(&mut self, path: &str) -> RequestBuilder<'_>

Build a DELETE request.

Source

pub fn request(&mut self, method: Method, path: &str) -> RequestBuilder<'_>

Build a request with the given method.

Source

pub fn get_raw(&mut self, path: &str) -> RequestBuilder<'_, Headers>

Build a GET with a pre-formed URL path (including any query string).

Skips the Query phase — returns Headers directly.

Source

pub fn post_raw(&mut self, path: &str) -> RequestBuilder<'_, Headers>

Build a POST with a pre-formed URL path.

Source

pub fn put_raw(&mut self, path: &str) -> RequestBuilder<'_, Headers>

Build a PUT with a pre-formed URL path.

Source

pub fn delete_raw(&mut self, path: &str) -> RequestBuilder<'_, Headers>

Build a DELETE with a pre-formed URL path.

Source

pub fn request_raw( &mut self, method: Method, path: &str, ) -> RequestBuilder<'_, Headers>

Build a request with a pre-formed URL path.

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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V