Trait AsSendBody

pub trait AsSendBody: Private { }
Available on crate feature dep_ureq only.
Expand description

Trait for common types to send in POST, PUT or PATCH.

Sending common data types such as String, &str or &[u8] require no further wrapping and can be sent either by RequestBuilder::send() or using the http crate Request directly (see example below).

Implemented for:

  • &str
  • &String
  • &Vec<u8>
  • &File
  • &TcpStream
  • &[u8]
  • Response<Body>
  • String
  • Vec<u8>
  • File
  • Stdin
  • TcpStream
  • UnixStream (not on windows)
  • &[u8; N]
  • ()

§Example

These two examples are equivalent.

let data: &[u8] = b"My special request body data";

let response = ureq::post("https://httpbin.org/post")
    .send(data)?;

Using http crate API

use ureq::http;

let data: &[u8] = b"My special request body data";

let request = http::Request::post("https://httpbin.org/post")
    .body(data)?;

let response = ureq::run(request)?;

Implementations on Foreign Types§

§

impl AsSendBody for &str

§

impl AsSendBody for &[u8]

§

impl AsSendBody for ()

§

impl<const N: usize> AsSendBody for &[u8; N]

Implementors§