Skip to main content

api_post

Macro api_post 

Source
macro_rules! api_post {
    (
        $(#[$m:meta])*
        $fn_name:ident,
        $op_id:literal,
        $visibility:expr,
        $ret_type:ty,
        $( ($param:ident: $param_t:ty) => $replace:literal ),*,
        $body_param:ident: $param_type:ty,
    ) => { ... };
}
Expand description

Create a function for calling a single endpoint with a POST request.

Follows the structure of the api_get! macro, with the addition of taking an additional pair of ident and ty to name and type the data that will be passed to serde_json::to_string for serializing for setting the request’s body.

§Example

pub struct SomeGroup<'a> {
    pub(crate) esi: &'a Esi,
}

impl SomeGroup<'_> {

    api_post!(
        /// Docs for the generated function
        function_name,
        "some_operation_id",
        RequestType::Public,
        Vec<u64>,
        (alliance_id: u64) => "{alliance_id}",
        ids: &[u64],
    );

}

§Result:

ⓘ
/// Docs for the generated function
pub async fn function_name(&self, alliance_id: u64, ids: &[u64]) -> EsiResult<Vec<u64>> {
    let path = self.esi.get_endpoint_for_op_id("some_operation_id")?
        .replace("{alliance_id}", &alliance_id.to_string());
    let body = serde_json::to_string(ids);
    self.esi
        .query("GET", RequestType::Public, &path, None, Some(&body))
        .await
}