pub struct Request { /* private fields */ }Expand description
An HTTP request.
Construct with Request::new and configure using the builder methods.
Implementations§
Source§impl Request
impl Request
Sourcepub fn new(url: impl Into<String>, verb: impl Into<String>) -> Self
pub fn new(url: impl Into<String>, verb: impl Into<String>) -> Self
Create a new request with no body and no authorization.
§Examples
Build a GET request:
use momento_functions_http::Request;
let request = Request::new("https://example.com/api", "GET");Sourcepub fn with_header(
self,
name: impl Into<String>,
value: impl Into<String>,
) -> Self
pub fn with_header( self, name: impl Into<String>, value: impl Into<String>, ) -> Self
Add a header to the request.
Sourcepub fn with_headers<K, V>(
self,
headers: impl IntoIterator<Item = (K, V)>,
) -> Self
pub fn with_headers<K, V>( self, headers: impl IntoIterator<Item = (K, V)>, ) -> Self
Add multiple headers to the request at once.
§Examples
use momento_functions_http::Request;
let request = Request::new("https://example.com/api", "POST")
.with_headers([
("Content-Type", "application/json"),
("Accept", "application/json"),
]);Sourcepub fn json<T: Serialize>(self, body: Json<T>) -> Result<Self, Error>
pub fn json<T: Serialize>(self, body: Json<T>) -> Result<Self, Error>
Set the request body to a JSON-serialized value, and set the
content-type header to application/json.
§Examples
use momento_functions_http::Request;
use momento_functions_bytes::encoding::Json;
#[derive(serde::Serialize)]
struct Payload { message: String }
let request = match Request::new("https://example.com/api", "POST")
.json(Json(Payload { message: "hello".to_string() }))
{
Ok(request) => request,
Err(e) => {
eprintln!("failed to serialize body: {e}");
return;
}
};Set the authorization strategy.
Auto Trait Implementations§
impl !Freeze for Request
impl RefUnwindSafe for Request
impl Send for Request
impl Sync for Request
impl Unpin for Request
impl UnsafeUnpin for Request
impl UnwindSafe for Request
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more