pub struct RequestBuilder { /* private fields */ }Expand description
Implementations§
Source§impl RequestBuilder
impl RequestBuilder
Sourcepub fn content_type(self, content_type: &str) -> Self
pub fn content_type(self, content_type: &str) -> Self
Sourcepub fn bearer_token(self, token: &str) -> Self
pub fn bearer_token(self, token: &str) -> Self
Sourcepub fn user_agent(self, user_agent: &str) -> Self
pub fn user_agent(self, user_agent: &str) -> Self
Sourcepub fn json<T: Serialize>(self, json: &T) -> Result<Self, BaseError>
pub fn json<T: Serialize>(self, json: &T) -> Result<Self, BaseError>
设置 JSON 请求体
§参数
json: 可序列化为 JSON 的数据
§返回
Ok(Self): 设置成功Err(BaseError): 序列化失败
§示例
ⓘ
#[derive(Serialize)]
struct User {
name: String,
email: String,
}
let user = User {
name: "Alice".to_string(),
email: "alice@example.com".to_string(),
};
let response = client
.post("https://api.example.com/users")
.json(&user)?
.send()
.await?;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<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
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>
Converts
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>
Converts
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 more