Struct RequestExecutor

Source
pub struct RequestExecutor;
Expand description

通用请求执行器,统一处理API调用逻辑 消除重复的请求-响应处理代码,提供统一的API调用入口

Implementations§

Source§

impl RequestExecutor

Source

pub async fn get<T: ApiResponseTrait>( config: &Config, path: &str, supported_tokens: Vec<AccessTokenType>, query_params: Option<HashMap<String, String>>, option: Option<RequestOption>, ) -> SDKResult<BaseResponse<T>>

执行GET请求

Source

pub async fn post<T: ApiResponseTrait, B: Serialize>( config: &Config, path: &str, supported_tokens: Vec<AccessTokenType>, body: Option<B>, option: Option<RequestOption>, ) -> SDKResult<BaseResponse<T>>

执行POST请求

Source

pub async fn put<T: ApiResponseTrait, B: Serialize>( config: &Config, path: &str, supported_tokens: Vec<AccessTokenType>, body: Option<B>, option: Option<RequestOption>, ) -> SDKResult<BaseResponse<T>>

执行PUT请求

Source

pub async fn delete<T: ApiResponseTrait>( config: &Config, path: &str, supported_tokens: Vec<AccessTokenType>, option: Option<RequestOption>, ) -> SDKResult<BaseResponse<T>>

执行DELETE请求

Source

pub async fn patch<T: ApiResponseTrait, B: Serialize>( config: &Config, path: &str, supported_tokens: Vec<AccessTokenType>, body: Option<B>, option: Option<RequestOption>, ) -> SDKResult<BaseResponse<T>>

执行PATCH请求

Source

pub async fn execute<T: ApiResponseTrait, B: Serialize>( config: &Config, method: Method, path: &str, supported_tokens: Vec<AccessTokenType>, query_params: Option<HashMap<String, String>>, body: Option<B>, option: Option<RequestOption>, ) -> SDKResult<BaseResponse<T>>

通用请求执行器核心方法

§参数
  • config: 应用配置,包含认证信息
  • method: HTTP方法
  • path: API路径
  • supported_tokens: 支持的访问令牌类型
  • query_params: 查询参数(可选)
  • body: 请求体(可选)
  • option: 请求选项(可选)
§返回值

返回标准的BaseResponse<T>格式响应

§示例
// GET请求
let response: BaseResponse<MessageList> = RequestExecutor::execute(
    &config,
    Method::GET,
    "/open-apis/im/v1/messages",
    vec![AccessTokenType::Tenant, AccessTokenType::User],
    Some(query_params),
    None::<()>,
    None,
).await?;

// POST请求
let response: BaseResponse<Message> = RequestExecutor::execute(
    &config,
    Method::POST,
    "/open-apis/im/v1/messages",
    vec![AccessTokenType::Tenant, AccessTokenType::User],
    None,
    Some(create_request),
    None,
).await?;
Source

pub async fn execute_with_path_params<T: ApiResponseTrait, B: Serialize>( config: &Config, method: Method, path_template: &str, path_params: HashMap<&str, &str>, supported_tokens: Vec<AccessTokenType>, query_params: Option<HashMap<String, String>>, body: Option<B>, option: Option<RequestOption>, ) -> SDKResult<BaseResponse<T>>

带路径参数的请求执行器 支持在路径中动态替换参数,如 /open-apis/im/v1/messages/{message_id}

§参数
  • path_template: 包含占位符的路径模板,如 “/open-apis/im/v1/messages/{message_id}”
  • path_params: 路径参数映射,如 HashMap::from([(“message_id”, “om_xxx”)])
  • 其他参数同 execute 方法
§示例
let path_params = HashMap::from([("message_id", "om_xxx")]);
let response = RequestExecutor::execute_with_path_params(
    &config,
    Method::GET,
    "/open-apis/im/v1/messages/{message_id}",
    path_params,
    vec![AccessTokenType::Tenant],
    None,
    None::<()>,
    None,
).await?;
Source

pub async fn json_request<T: ApiResponseTrait, B: Serialize>( config: &Config, method: Method, path: &str, body: &B, option: Option<RequestOption>, ) -> SDKResult<BaseResponse<T>>

简化的JSON请求执行器 自动序列化JSON请求体并设置标准的租户/用户令牌支持

§示例
// 创建消息
let response = RequestExecutor::json_request::<CreateMessageResponse, _>(
    &config,
    Method::POST,
    "/open-apis/im/v1/messages",
    &create_message_request,
    None,
).await?;
Source

pub async fn query_request<T: ApiResponseTrait>( config: &Config, path: &str, query_params: Option<HashMap<String, String>>, option: Option<RequestOption>, ) -> SDKResult<BaseResponse<T>>

简化的查询请求执行器 用于GET请求,自动设置标准的租户/用户令牌支持

§示例
// 获取消息列表
let mut query_params = HashMap::new();
query_params.insert("container_id".to_string(), chat_id);
let response = RequestExecutor::query_request::<MessageListResponse>(
    &config,
    "/open-apis/im/v1/messages",
    Some(query_params),
    None,
).await?;

Auto Trait Implementations§

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> 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> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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
Source§

impl<T> ErasedDestructor for T
where T: 'static,