Macro apisdk::send

source ·
macro_rules! send {
    ($req:expr) => { ... };
    ($req:expr, ()) => { ... };
    ($req:expr, Body) => { ... };
    ($req:expr, Json) => { ... };
    ($req:expr, Xml) => { ... };
    ($req:expr, Text) => { ... };
    ($req:expr, $parser:ty, ()) => { ... };
    ($req:expr, Json<$ve:ty>) => { ... };
    ($req:expr, $ve:ty) => { ... };
    ($req:expr, $parser:ty, $vet:ty, $ve:ty) => { ... };
}
Expand description

Send request

§Forms

  • send!(req) -> impl Future<Output = ApiResult<T>>
    • send the request, and parse response as json or xml based on response
  • send!(req, ()) -> impl Future<Output = ApiResult<()>>
    • send the request, verify response status, then discard response
  • send!(req, Body) -> impl Future<Output = ApiResult<apisdk::ResponseBody>>
    • send the request, verify response status, and decode response body
  • send!(req, Json) -> impl Future<Output = ApiResult<T>>
    • send the request, parse response as json, then use serde_json to deserialize it
  • send!(req, Xml) -> impl Future<Output = ApiResult<T>>
    • send the request, parse response as xml, then use quick_xml to deserialize it
  • send!(req, Text) -> impl Future<Output = ApiResult<T>>
    • send the request, parse response as text, then use FromStr to deserialize it
  • send!(req, OtherType) -> impl Future<Output = ApiResult<T>>
    • send the request, parse response as json, and use OtherType as JsonExtractor
  • send!(req, Json<OtherType>) -> impl Future<Output = ApiResult<T>>
    • send the request, parse response as json, and use OtherType as JsonExtractor

§Built-in JsonExtractors

  • std::string::String
    • treat whole payload as text output
  • serde_json::Value
    • treat whole payload as json output
  • apisdk::WholePayload
    • an alias of serde_json::Value
  • apisdk::CodeDataMessage
    • parse {code, data, message} json payload, verify code, and return data field

§Examples

use serde::Deserialize;

#[derive(Deserialize)]
struct TypeOfResponse {}

let req = self.get("/path/api").await?;
let res: TypeOfResponse = send!(req).await?;