pub struct EndpointRequestBuilder<'a, E: Endpoint, S> { /* private fields */ }Expand description
Fluent builder for a typed Endpoint.
When E::Params is not [()], the builder starts in NeedsParams and requires
.params() before .send_json().
When E::Query is not [()], .query() is still optional — it only runs when called.
In Ready state, use .query(E::Query) for typed query structs, or the forwarded
methods on this type (.header, .json, etc.). Prefer typed .query() over string keys on Deref.
Implementations§
Source§impl<'a, E: Endpoint> EndpointRequestBuilder<'a, E, NeedsParams>
impl<'a, E: Endpoint> EndpointRequestBuilder<'a, E, NeedsParams>
Sourcepub fn params(
self,
params: E::Params,
) -> EndpointRequestBuilder<'a, E, ParamsBuilderStateAfter<E>>where
E::Body: EndpointBody,
pub fn params(
self,
params: E::Params,
) -> EndpointRequestBuilder<'a, E, ParamsBuilderStateAfter<E>>where
E::Body: EndpointBody,
Applies typed path parameters and transitions to the next builder state.
Source§impl<'a, E: Endpoint> EndpointRequestBuilder<'a, E, NeedsBody>
impl<'a, E: Endpoint> EndpointRequestBuilder<'a, E, NeedsBody>
pub fn new_needs_body(inner: RequestBuilder<'a>) -> Self
Sourcepub fn json<T: Serialize>(
self,
body: &T,
) -> Result<EndpointRequestBuilder<'a, E, Ready>>
Available on crate feature json only.
pub fn json<T: Serialize>( self, body: &T, ) -> Result<EndpointRequestBuilder<'a, E, Ready>>
json only.JSON request body (transitions to Ready).
Sourcepub fn json_validated<T>(
self,
body: &T,
) -> Result<EndpointRequestBuilder<'a, E, Ready>>
Available on crate feature validate only.
pub fn json_validated<T>( self, body: &T, ) -> Result<EndpointRequestBuilder<'a, E, Ready>>
validate only.Validated JSON request body (feature validate).
Source§impl<'a, E: Endpoint> EndpointRequestBuilder<'a, E, Ready>
impl<'a, E: Endpoint> EndpointRequestBuilder<'a, E, Ready>
Sourcepub fn query(self, query: E::Query) -> Result<Self>
pub fn query(self, query: E::Query) -> Result<Self>
Applies typed query parameters for E::Query.
Optional at compile time: you can call .send_json() without this method;
no query string from E::Query is sent unless you call .query(...).
Returns Error::QuerySerialize when serde serialization fails
(since 0.4.0 — failures are no longer ignored).
§Examples
define_params!(ItemParams for "/items/:id" { id: u64 });
#[derive(Default, Serialize)]
struct ItemQuery { tag: Option<String> }
better_fetch::impl_serde_endpoint_query!(ItemQuery);
struct GetItem;
impl Endpoint for GetItem {
const METHOD: Method = Method::GET;
const PATH: &'static str = "/items/:id";
type Response = serde_json::Value;
type Params = ItemParams;
type Query = ItemQuery;
type Body = ();
type Headers = ();
}
let client = Client::new("https://api.example.com")?;
let _ = client
.call::<GetItem>()
.params(ItemParams { id: 1 })
.query(ItemQuery { tag: Some("news".into()) })?
.send_json()
.await?;Sourcepub fn query_validated(self, query: E::Query) -> Result<Self>
Available on crate features json and validate only.
pub fn query_validated(self, query: E::Query) -> Result<Self>
json and validate only.Like Self::query but runs garde::Validate on the query value first (feature validate).
Intended for serde query structs (including those using EndpointQueryDerive).
Sourcepub fn header(
self,
key: impl AsRef<str>,
value: impl AsRef<str>,
) -> Result<Self>
pub fn header( self, key: impl AsRef<str>, value: impl AsRef<str>, ) -> Result<Self>
Adds a request header.
Sourcepub fn bearer_token(self, token: impl Into<String>) -> Self
pub fn bearer_token(self, token: impl Into<String>) -> Self
Sets bearer authentication.
Sourcepub fn cancellation_token(self, token: CancellationToken) -> Self
pub fn cancellation_token(self, token: CancellationToken) -> Self
Attaches a cancellation token.
Sourcepub fn throw_on_error(self, throw: bool) -> Self
pub fn throw_on_error(self, throw: bool) -> Self
When true, send returns Err on non-2xx.
Sourcepub fn base_url(self, base_url: impl AsRef<str>) -> Result<Self>
pub fn base_url(self, base_url: impl AsRef<str>) -> Result<Self>
Overrides the client base URL for this request (RequestBuilder::base_url).
Sourcepub fn retry(self, policy: RetryPolicy) -> Self
pub fn retry(self, policy: RetryPolicy) -> Self
Overrides retry policy (RequestBuilder::retry).
Sourcepub fn timeout(self, timeout: Duration) -> Self
pub fn timeout(self, timeout: Duration) -> Self
Overrides timeout (RequestBuilder::timeout).
Sourcepub async fn send_stream(self) -> Result<StreamingResponse>
pub async fn send_stream(self) -> Result<StreamingResponse>
Streaming execution (RequestBuilder::send_stream).
Sourcepub fn max_response_bytes(self, limit: u64) -> Self
pub fn max_response_bytes(self, limit: u64) -> Self
Caps response body size (RequestBuilder::max_response_bytes).
Sourcepub fn disable_validation(self, disable: bool) -> Self
Available on crate feature schema-validate only.
pub fn disable_validation(self, disable: bool) -> Self
schema-validate only.Skips registry JSON Schema validation for this request (RequestBuilder::disable_validation).
Sourcepub fn json<T: Serialize>(self, body: &T) -> Result<Self>
Available on crate feature json only.
pub fn json<T: Serialize>(self, body: &T) -> Result<Self>
json only.JSON request body (RequestBuilder::json).
Sourcepub fn json_validated<T>(self, body: &T) -> Result<Self>
Available on crate feature validate only.
pub fn json_validated<T>(self, body: &T) -> Result<Self>
validate only.Validated JSON request body (feature validate).
Sourcepub fn body(self, body: impl Into<Bytes>) -> Self
pub fn body(self, body: impl Into<Bytes>) -> Self
Raw request body (RequestBuilder::body).
Sourcepub fn with_headers(self, headers: E::Headers) -> Result<Self>
pub fn with_headers(self, headers: E::Headers) -> Result<Self>
Applies typed headers for E::Headers.
Sourcepub fn with_headers_validated(self, headers: E::Headers) -> Result<Self>
Available on crate feature validate only.
pub fn with_headers_validated(self, headers: E::Headers) -> Result<Self>
validate only.Like Self::with_headers but runs garde::Validate on the headers value first (feature validate).
Sourcepub async fn send_json(self) -> Result<E::Response>
Available on crate feature json only.
pub async fn send_json(self) -> Result<E::Response>
json only.Executes and deserializes E::Response (feature json).
Sourcepub async fn send_api<T, ErrBody>(self) -> Result<Result<T, ErrBody>>where
T: DeserializeOwned,
ErrBody: DeserializeOwned,
Available on crate feature json only.
pub async fn send_api<T, ErrBody>(self) -> Result<Result<T, ErrBody>>where
T: DeserializeOwned,
ErrBody: DeserializeOwned,
json only.Success/error deserialization by status (feature json).