pub type AsyncRequestBuilder<'r, E> = RequestBuilder<'r, AsyncRequestBody<'r>, E>;
Expand description

异步请求构建器

Implementations§

设置 HTTP 请求体为异步输入流

设置 HTTP 请求体为异步输入流的可变引用

设置 HTTP 请求体为内存数据

Examples found in repository?
src/client/request/builder.rs (line 793)
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
    pub fn json(&mut self, body: impl Serialize) -> JsonResult<&mut Self> {
        Ok(self.bytes_as_body(serde_json::to_vec(&body)?, Some(APPLICATION_JSON)))
    }

    /// 设置 HTTP 请求体为表单对象
    #[inline]
    pub fn post_form<I, K, V>(&mut self, iter: I) -> &mut Self
    where
        I: IntoIterator,
        I::Item: Borrow<(K, Option<V>)>,
        K: AsRef<str>,
        V: AsRef<str>,
    {
        let mut form = form_urlencoded::Serializer::new(String::new());
        for pair in iter {
            let (k, v) = pair.borrow();
            if let Some(v) = v {
                form.append_pair(k.as_ref(), v.as_ref());
            } else {
                form.append_key_only(k.as_ref());
            }
        }
        self.bytes_as_body(form.finish().into_bytes(), Some(APPLICATION_WWW_FORM_URLENCODED))
    }

    /// 设置 HTTP 请求体为 Multipart 表单对象
    #[inline]
    pub async fn multipart<'a>(
        &mut self,
        multipart: impl Into<AsyncMultipart<'a>>,
    ) -> IoResult<&mut RequestBuilder<'r, AsyncRequestBody<'r>, E>> {
        use futures::AsyncReadExt;

        let mut buf = Vec::new();
        let multipart = multipart.into();
        let mime = ("multipart/form-data; boundary=".to_owned() + multipart.boundary())
            .parse()
            .unwrap();
        multipart.into_async_read().read_to_end(&mut buf).await?;
        Ok(self.bytes_as_body(buf, Some(mime)))
    }

设置 HTTP 请求体为内存数据的引用

设置 HTTP 请求体为 JSON 对象

设置 HTTP 请求体为表单对象

设置 HTTP 请求体为 Multipart 表单对象

异步发起 HTTP 请求

Examples found in repository?
src/regions/regions_provider/all_regions_provider.rs (line 277)
270
271
272
273
274
275
276
277
278
279
280
281
282
        async fn do_async_query(&self) -> ApiResult<GotRegions> {
            handle_response_body(
                self.http_client
                    .async_get(&[ServiceName::Uc], &self.uc_endpoints)
                    .path("/regions")
                    .authorization(Authorization::v2(&self.credential_provider))
                    .accept_json()
                    .call()
                    .await?
                    .parse_json::<ResponseBody>()
                    .await?,
            )
        }
More examples
Hide additional examples
src/regions/regions_provider/bucket_regions_queryer.rs (line 310)
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
    async fn do_async_query(&self) -> ApiResult<GotRegions> {
        handle_response_body(
            self.queryer
                .http_client
                .async_get(&[ServiceName::Uc, ServiceName::Api], &self.queryer.uc_endpoints)
                .path("/v4/query")
                .append_query_pair("ak", self.access_key.as_str())
                .append_query_pair("bucket", self.bucket_name.as_str())
                .accept_json()
                .call()
                .await?
                .parse_json::<ResponseBody>()
                .await?,
        )
    }
src/regions/endpoints_provider/bucket_domains_provider.rs (line 300)
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
    async fn do_async_query(&self) -> ApiResult<Endpoints> {
        let endpoints: Endpoints = self
            .queryer
            .http_client
            .async_get(&[ServiceName::Uc], &self.queryer.uc_endpoints)
            .path("/v2/domains")
            .authorization(Authorization::v2(&self.credential))
            .append_query_pair("tbl", self.bucket_name.as_str())
            .accept_json()
            .call()
            .await?
            .parse_json::<Vec<String>>()
            .await?
            .into_body()
            .into_iter()
            .map(Endpoint::from)
            .collect();
        Ok(endpoints)
    }