Skip to main content

ncm_api_rs/api/
batch.rs

1use super::Query;
2use crate::error::Result;
3/// 批量请求接口
4/// 对应 Node.js module/batch.js
5use crate::request::{ApiClient, ApiResponse, CryptoType};
6use serde_json::json;
7
8impl ApiClient {
9    /// 批量请求接口
10    /// 对应 /batch
11    pub async fn batch(&self, query: &Query) -> Result<ApiResponse> {
12        let mut data = json!({});
13        let map = data.as_object_mut().unwrap();
14        for (key, value) in &query.params {
15            if key.starts_with("/api/") {
16                map.insert(
17                    key.to_string(),
18                    serde_json::Value::String(value.to_string()),
19                );
20            }
21        }
22        self.request("/api/batch", data, query.to_option(CryptoType::default()))
23            .await
24    }
25}