pub struct RequestBuilder { /* private fields */ }core only.Expand description
Builder for constructing Request instances.
Provides a fluent API for building HTTP requests with optional parameters.
§Examples
use reinhardt_http::Request;
use hyper::Method;
let request = Request::builder()
.method(Method::GET)
.uri("/api/users?page=1")
.build()
.unwrap();
assert_eq!(request.method, Method::GET);
assert_eq!(request.path(), "/api/users");
assert_eq!(request.query_params.get("page"), Some(&"1".to_string()));Implementations§
Source§impl RequestBuilder
impl RequestBuilder
Sourcepub fn method(self, method: Method) -> RequestBuilder
pub fn method(self, method: Method) -> RequestBuilder
Set the HTTP method.
§Examples
use reinhardt_http::Request;
use hyper::Method;
let request = Request::builder()
.method(Method::POST)
.uri("/api/users")
.build()
.unwrap();
assert_eq!(request.method, Method::POST);Sourcepub fn uri<T>(self, uri: T) -> RequestBuilder
pub fn uri<T>(self, uri: T) -> RequestBuilder
Set the request URI.
Accepts either a &str or Uri. Query parameters will be automatically parsed.
§Examples
use reinhardt_http::Request;
use hyper::Method;
let request = Request::builder()
.method(Method::GET)
.uri("/api/users?page=1&limit=10")
.build()
.unwrap();
assert_eq!(request.path(), "/api/users");
assert_eq!(request.query_params.get("page"), Some(&"1".to_string()));
assert_eq!(request.query_params.get("limit"), Some(&"10".to_string()));Sourcepub fn version(self, version: Version) -> RequestBuilder
pub fn version(self, version: Version) -> RequestBuilder
Set the HTTP version.
Defaults to HTTP/1.1 if not specified.
§Examples
use reinhardt_http::Request;
use hyper::{Method, Version};
let request = Request::builder()
.method(Method::GET)
.uri("/api/users")
.version(Version::HTTP_2)
.build()
.unwrap();
assert_eq!(request.version, Version::HTTP_2);Sourcepub fn headers(self, headers: HeaderMap) -> RequestBuilder
pub fn headers(self, headers: HeaderMap) -> RequestBuilder
Set the request headers.
Replaces all existing headers.
§Examples
use reinhardt_http::Request;
use hyper::{Method, HeaderMap, header};
let mut headers = HeaderMap::new();
headers.insert(header::CONTENT_TYPE, "application/json".parse().unwrap());
let request = Request::builder()
.method(Method::POST)
.uri("/api/users")
.headers(headers.clone())
.build()
.unwrap();
assert_eq!(request.headers.get(header::CONTENT_TYPE).unwrap(), "application/json");Sourcepub fn header<K, V>(self, key: K, value: V) -> RequestBuilder
pub fn header<K, V>(self, key: K, value: V) -> RequestBuilder
Add a single header to the request.
§Examples
use reinhardt_http::Request;
use hyper::{Method, header};
let request = Request::builder()
.method(Method::POST)
.uri("/api/users")
.header(header::CONTENT_TYPE, "application/json")
.header(header::AUTHORIZATION, "Bearer token123")
.build()
.unwrap();
assert_eq!(request.headers.get(header::CONTENT_TYPE).unwrap(), "application/json");
assert_eq!(request.headers.get(header::AUTHORIZATION).unwrap(), "Bearer token123");Sourcepub fn body(self, body: Bytes) -> RequestBuilder
pub fn body(self, body: Bytes) -> RequestBuilder
Set the request body.
§Examples
use reinhardt_http::Request;
use hyper::Method;
use bytes::Bytes;
let body = Bytes::from(r#"{"name":"Alice"}"#);
let request = Request::builder()
.method(Method::POST)
.uri("/api/users")
.body(body.clone())
.build()
.unwrap();
assert_eq!(request.body(), &body);Sourcepub fn secure(self, is_secure: bool) -> RequestBuilder
pub fn secure(self, is_secure: bool) -> RequestBuilder
Set whether the request is secure (HTTPS).
Defaults to false if not specified.
§Examples
use reinhardt_http::Request;
use hyper::Method;
let request = Request::builder()
.method(Method::GET)
.uri("/")
.secure(true)
.build()
.unwrap();
assert!(request.is_secure());
assert_eq!(request.scheme(), "https");Sourcepub fn remote_addr(self, addr: SocketAddr) -> RequestBuilder
pub fn remote_addr(self, addr: SocketAddr) -> RequestBuilder
Set the remote address of the client.
§Examples
use reinhardt_http::Request;
use hyper::Method;
use std::net::{SocketAddr, IpAddr, Ipv4Addr};
let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080);
let request = Request::builder()
.method(Method::GET)
.uri("/")
.remote_addr(addr)
.build()
.unwrap();
assert_eq!(request.remote_addr, Some(addr));Sourcepub fn parser<P>(self, parser: P) -> RequestBuilderwhere
P: Parser + 'static,
Available on crate feature parsers only.
pub fn parser<P>(self, parser: P) -> RequestBuilderwhere
P: Parser + 'static,
parsers only.Add a parser to the request.
Parsers are used to parse the request body into specific formats. The parser will be boxed internally.
§Examples
use reinhardt_http::Request;
use hyper::Method;
let request = Request::builder()
.method(Method::POST)
.uri("/api/users")
.parser(JsonParser::new())
.build()
.unwrap();Sourcepub fn path_params(self, params: HashMap<String, String>) -> RequestBuilder
pub fn path_params(self, params: HashMap<String, String>) -> RequestBuilder
Set path parameters (used for testing views without router).
This is primarily useful in test environments where you need to simulate path parameters that would normally be extracted by the router.
§Examples
use reinhardt_http::Request;
use hyper::Method;
use std::collections::HashMap;
let mut params = HashMap::new();
params.insert("id".to_string(), "42".to_string());
let request = Request::builder()
.method(Method::GET)
.uri("/api/users/42")
.path_params(params)
.build()
.unwrap();
assert_eq!(request.path_params.get("id"), Some(&"42".to_string()));Sourcepub fn build(self) -> Result<Request, String>
pub fn build(self) -> Result<Request, String>
Build the final Request instance.
Returns an error if the URI is missing.
§Examples
use reinhardt_http::Request;
use hyper::Method;
let request = Request::builder()
.method(Method::GET)
.uri("/api/users")
.build()
.unwrap();
assert_eq!(request.method, Method::GET);
assert_eq!(request.path(), "/api/users");Trait Implementations§
Source§impl Default for RequestBuilder
impl Default for RequestBuilder
Source§fn default() -> RequestBuilder
fn default() -> RequestBuilder
Auto Trait Implementations§
impl !Freeze for RequestBuilder
impl !RefUnwindSafe for RequestBuilder
impl Send for RequestBuilder
impl Sync for RequestBuilder
impl Unpin for RequestBuilder
impl UnsafeUnpin for RequestBuilder
impl !UnwindSafe for RequestBuilder
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> IntoResult<T> for T
impl<T> IntoResult<T> for T
type Err = Infallible
fn into_result(self) -> Result<T, <T as IntoResult<T>>::Err>
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.