pub struct RequestBuilder<'a> { /* private fields */ }Expand description
Implementations§
Source§impl<'a> RequestBuilder<'a>
impl<'a> RequestBuilder<'a>
Sourcepub fn json<T: Serialize>(self, body: T) -> JsonRequestBuilder<'a, T>
pub fn json<T: Serialize>(self, body: T) -> JsonRequestBuilder<'a, T>
Attaches a JSON-serialisable body, transitioning to JsonRequestBuilder.
§Example
let item: Item = client
.post("/items")
.json(NewItem { name: "widget".to_string() })
.send()
.await?;Sourcepub fn query<T: Serialize>(self, params: T) -> QueryRequestBuilder<'a, T>
pub fn query<T: Serialize>(self, params: T) -> QueryRequestBuilder<'a, T>
Attaches query parameters that serialise into the URL query string, transitioning to
QueryRequestBuilder.
§Example
let results: SearchResult = client
.get("/search")
.query(SearchParams { q: "rust".to_string(), page: 1 })
.send()
.await?;Sourcepub async fn send<R: DeserializeOwned>(self) -> Result<R, Error>
pub async fn send<R: DeserializeOwned>(self) -> Result<R, Error>
Sends the request asynchronously and deserialises the response body as R.
§Example
let user: User = client.get("/users/1").send().await?;Sourcepub fn send_sync<R: DeserializeOwned>(self) -> Result<R, Error>
pub fn send_sync<R: DeserializeOwned>(self) -> Result<R, Error>
Sends the request synchronously and deserialises the response body as R.
§Example
let user: User = client.get("/users/1").send_sync()?;Sourcepub fn encryption<T: Encode>(
self,
body: T,
key: SerializationKey,
) -> EncryptedBodyRequestBuilder<'a, T>
pub fn encryption<T: Encode>( self, body: T, key: SerializationKey, ) -> EncryptedBodyRequestBuilder<'a, T>
Attaches a VEIL-sealed body, transitioning to EncryptedBodyRequestBuilder.
The body is VEIL-sealed with the given SerializationKey and sent as
application/octet-stream; the response is opened with the same key.
For plain-JSON routes use .json(body) instead.
§Example
use toolkit_zero::socket::SerializationKey;
let resp: Resp = client
.post("/compute")
.encryption(Req { value: 42 }, SerializationKey::Default)
.send()
.await?;Sourcepub fn encrypted_query<T: Encode>(
self,
params: T,
key: SerializationKey,
) -> EncryptedQueryRequestBuilder<'a, T>
pub fn encrypted_query<T: Encode>( self, params: T, key: SerializationKey, ) -> EncryptedQueryRequestBuilder<'a, T>
Attaches VEIL-sealed query parameters, transitioning to EncryptedQueryRequestBuilder.
The params are VEIL-sealed and sent as ?data=<base64url>; the response is opened
with the same key. For plain-JSON query routes use .query(params) instead.
§Example
use toolkit_zero::socket::SerializationKey;
let page: Page = client
.get("/items")
.encrypted_query(Filter { page: 1 }, SerializationKey::Default)
.send()
.await?;