Skip to main content

ApiRequest

Struct ApiRequest 

Source
pub struct ApiRequest<R> { /* private fields */ }
Expand description

简化的API请求结构

Implementations§

Source§

impl<R> ApiRequest<R>

Source

pub fn get(url: impl Into<String>) -> ApiRequest<R>

Source

pub fn post(url: impl Into<String>) -> ApiRequest<R>

Source

pub fn put(url: impl Into<String>) -> ApiRequest<R>

Source

pub fn patch(url: impl Into<String>) -> ApiRequest<R>

Source

pub fn delete(url: impl Into<String>) -> ApiRequest<R>

Source

pub fn header<K, V>(self, key: K, value: V) -> ApiRequest<R>
where K: Into<String>, V: Into<String>,

Source

pub fn query<K, V>(self, key: K, value: V) -> ApiRequest<R>
where K: Into<String>, V: Into<String>,

Source

pub fn query_opt<K, V>(self, key: K, value: Option<V>) -> ApiRequest<R>
where K: Into<String>, V: Into<String>,

添加可选查询参数,如果值为None则跳过

Source

pub fn body(self, body: impl Into<RequestData>) -> ApiRequest<R>

Source

pub fn file_content(self, file: Vec<u8>) -> ApiRequest<R>

设置文件内容 (用于 multipart 上传)

Source

pub fn json_body<T>(self, body: &T) -> ApiRequest<R>
where T: Serialize,

为任何可序列化的类型设置请求体

Source

pub fn timeout(self, duration: Duration) -> ApiRequest<R>

Source

pub fn build_url(&self) -> String

Source

pub fn method(&self) -> &HttpMethod

Source

pub fn api_path(&self) -> &str

Source

pub fn supported_access_token_types(&self) -> Vec<AccessTokenType>

Source

pub fn to_bytes(&self) -> Vec<u8>

Source

pub fn headers_mut(&mut self) -> &mut HashMap<String, String>

获取 headers 的可变引用,用于直接插入多个 header

Source

pub fn query_mut(&mut self) -> &mut HashMap<String, String>

获取 query 的可变引用,用于直接插入多个查询参数

Source

pub fn file(&self) -> Vec<u8>

Source

pub fn request_option(self, option: RequestOption) -> ApiRequest<R>

应用请求选项(兼容方法)

Source

pub fn query_param<K, V>(self, key: K, value: V) -> ApiRequest<R>
where K: Into<String>, V: Into<String>,

设置查询参数(兼容方法)

Source

pub fn query_params<I, K, V>(self, params: I) -> ApiRequest<R>
where I: IntoIterator<Item = (K, V)>, K: Into<String>, V: Into<String>,

设置多个查询参数(兼容方法)

Trait Implementations§

Source§

impl<R> Clone for ApiRequest<R>
where R: Clone,

Source§

fn clone(&self) -> ApiRequest<R>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<R> Debug for ApiRequest<R>
where R: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<R> Default for ApiRequest<R>

Source§

fn default() -> ApiRequest<R>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<R> Freeze for ApiRequest<R>

§

impl<R> RefUnwindSafe for ApiRequest<R>
where R: RefUnwindSafe,

§

impl<R> Send for ApiRequest<R>
where R: Send,

§

impl<R> Sync for ApiRequest<R>
where R: Sync,

§

impl<R> Unpin for ApiRequest<R>
where R: Unpin,

§

impl<R> UnsafeUnpin for ApiRequest<R>

§

impl<R> UnwindSafe for ApiRequest<R>
where R: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more