pub struct Request { /* private fields */ }Expand description
Re-export worker types for convenience A Request representation for handling incoming and creating outbound HTTP requests.
Implementations§
Source§impl Request
impl Request
Sourcepub fn new(uri: &str, method: Method) -> Result<Request, Error>
pub fn new(uri: &str, method: Method) -> Result<Request, Error>
Construct a new Request with an HTTP Method.
Sourcepub fn new_with_init(uri: &str, init: &RequestInit) -> Result<Request, Error>
pub fn new_with_init(uri: &str, init: &RequestInit) -> Result<Request, Error>
Construct a new Request with a RequestInit configuration.
Sourcepub async fn json<B>(&mut self) -> Result<B, Error>where
B: DeserializeOwned,
pub async fn json<B>(&mut self) -> Result<B, Error>where
B: DeserializeOwned,
Access this request’s body encoded as JSON.
Sourcepub async fn bytes(&mut self) -> Result<Vec<u8>, Error>
pub async fn bytes(&mut self) -> Result<Vec<u8>, Error>
Access this request’s body as raw bytes.
Sourcepub async fn form_data(&mut self) -> Result<FormData, Error>
pub async fn form_data(&mut self) -> Result<FormData, Error>
Access this request’s body as a form-encoded payload and pull out fields and files.
Sourcepub fn stream(&mut self) -> Result<ByteStream, Error>
pub fn stream(&mut self) -> Result<ByteStream, Error>
Access this request’s body as a Stream of bytes.
Sourcepub fn headers_mut(&mut self) -> Result<&mut Headers, Error>
pub fn headers_mut(&mut self) -> Result<&mut Headers, Error>
Get a mutable reference to this request’s Headers.
Note: they can only be modified if the request was created from scratch or cloned.
Sourcepub fn cf(&self) -> Option<&Cf>
pub fn cf(&self) -> Option<&Cf>
Access this request’s Cloudflare-specific properties.
§Note
Request objects constructed by the user and not the runtime will not have a Cf associated.
See workerd#825
Sourcepub fn path_mut(&mut self) -> Result<&mut String, Error>
pub fn path_mut(&mut self) -> Result<&mut String, Error>
Get a mutable reference to this request’s path. Note: they can only be modified if the request was created from scratch or cloned.
Sourcepub fn query<Q>(&self) -> Result<Q, Error>where
Q: DeserializeOwned,
pub fn query<Q>(&self) -> Result<Q, Error>where
Q: DeserializeOwned,
Deserialize the url query