[−][src]Struct ureq::Request
Request instances are builders that creates a request.
let response = ureq::get("http://example.com/form") .query("foo", "bar baz") // add ?foo=bar+baz .call()?; // run the request
Implementations
impl Request
[src]
pub fn call(self) -> Result<Response, Error>
[src]
Sends the request with no body and blocks the caller until done.
Use this with GET, HEAD, OPTIONS or TRACE. It sends neither Content-Length nor Transfer-Encoding.
let resp = ureq::get("http://example.com/") .call()?;
pub fn send_json(mut self: Self, data: SerdeValue) -> Result<Response, Error>
[src]
Send data a json value.
Requires feature ureq = { version = "*", features = ["json"] }
The Content-Length
header is implicitly set to the length of the serialized value.
let resp = ureq::post("http://httpbin.org/post") .send_json(ureq::json!({ "name": "martin", "rust": true, }))?;
pub fn send_bytes(self, data: &[u8]) -> Result<Response, Error>
[src]
Send data as bytes.
The Content-Length
header is implicitly set to the length of the serialized value.
let resp = ureq::put("http://httpbin.org/put") .send_bytes(&[0; 1000])?;
pub fn send_string(self, data: &str) -> Result<Response, Error>
[src]
Send data as a string.
The Content-Length
header is implicitly set to the length of the serialized value.
Defaults to utf-8
Charset support
Requires feature ureq = { version = "*", features = ["charset"] }
If a Content-Type
header is present and it contains a charset specification, we
attempt to encode the string using that character set. If it fails, we fall back
on utf-8.
// this example requires features = ["charset"] let resp = ureq::post("http://httpbin.org/post") .set("Content-Type", "text/plain; charset=iso-8859-1") .send_string("Hällo Wörld!")?;
pub fn send_form(
mut self: Self,
data: &[(&str, &str)]
) -> Result<Response, Error>
[src]
mut self: Self,
data: &[(&str, &str)]
) -> Result<Response, Error>
Send a sequence of (key, value) pairs as form-urlencoded data.
The Content-Type
header is implicitly set to application/x-www-form-urlencoded.
The Content-Length
header is implicitly set to the length of the serialized value.
let resp = ureq::post("http://httpbin.org/post") .send_form(&[ ("foo", "bar"), ("foo2", "bar2"), ])?;
pub fn send(self, reader: impl Read) -> Result<Response, Error>
[src]
Send data from a reader.
If no Content-Length and Transfer-Encoding header has been set, it uses the chunked transfer encoding.
The caller may set the Content-Length header to the expected byte size of the reader if is known.
The input from the reader is buffered into chunks of size 16,384, the max size of a TLS fragment.
use std::io::Cursor; let read = Cursor::new(vec![0x20; 100]); let resp = ureq::post("http://httpbin.org/post") .send(read)?;
pub fn set(mut self: Self, header: &str, value: &str) -> Self
[src]
Set a header field.
let resp = ureq::get("http://httpbin.org/bytes/1000") .set("Accept", "text/plain") .set("Range", "bytes=500-999") .call()?;
pub fn header(&self, name: &str) -> Option<&str>
[src]
Returns the value for a set header.
let req = ureq::get("/my_page") .set("X-API-Key", "foobar"); assert_eq!("foobar", req.header("x-api-Key").unwrap());
pub fn header_names(&self) -> Vec<String>
[src]
A list of the set header names in this request. Lowercased to be uniform.
let req = ureq::get("/my_page") .set("X-API-Key", "foobar") .set("Content-Type", "application/json"); assert_eq!(req.header_names(), vec!["x-api-key", "content-type"]);
pub fn has(&self, name: &str) -> bool
[src]
Tells if the header has been set.
let req = ureq::get("/my_page") .set("X-API-Key", "foobar"); assert_eq!(true, req.has("x-api-Key"));
pub fn all(&self, name: &str) -> Vec<&str>
[src]
All headers corresponding values for the give name, or empty vector.
let req = ureq::get("/my_page") .set("X-Forwarded-For", "1.2.3.4") .set("X-Forwarded-For", "2.3.4.5"); assert_eq!(req.all("x-forwarded-for"), vec![ "1.2.3.4", "2.3.4.5", ]);
pub fn query(mut self: Self, param: &str, value: &str) -> Self
[src]
Set a query parameter.
For example, to set ?format=json&dest=/login
let resp = ureq::get("http://httpbin.org/response-headers") .query("format", "json") .query("dest", "/login") .call()?;
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Request
[src]
impl Send for Request
[src]
impl Sync for Request
[src]
impl Unpin for Request
[src]
impl !UnwindSafe for Request
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,