Macro apisdk::send_json

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

Send the payload as JSON

§Forms

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

§Examples

let data = json!({
    "key": "value"
});
let req = client.post("/path/api").await?;
let res: TypeOfResponse = send_json!(req, data).await?;

Please reference send for more information