paystack/http/
base.rs

1use async_trait::async_trait;
2use serde_json::Value;
3use std::fmt::{Debug, Display};
4
5/// A predefined type for the query type in the HTTP client.
6pub type Query<'a> = Vec<(&'a str, &'a str)>;
7
8/// This trait is a collection of the stand HTTP methods for any client.
9/// The aim of the trait is to abstract ways the HTTP implementation found in
10/// different HTTP clients.
11///
12/// The goal is to give a level of flexibility to the user of the crate to work
13/// with their preferred HTTP client.
14/// To be as generic as possible, the U generic stands for the HTTP response.
15/// Ideally, it should be bounded to specific traits common in all response.
16
17#[async_trait]
18pub trait HttpClient: Debug + Default + Clone + Send {
19    /// HTTP error
20    type Error: Debug + Display;
21
22    /// Send http get request
23    async fn get(
24        &self,
25        url: &str,
26        api_key: &str,
27        query: Option<&Query>,
28    ) -> Result<String, Self::Error>;
29    /// Send http post request
30    async fn post(&self, url: &str, api_key: &str, body: &Value) -> Result<String, Self::Error>;
31    /// Send http put request
32    async fn put(&self, url: &str, api_key: &str, body: &Value) -> Result<String, Self::Error>;
33    /// Send http delete request
34    async fn delete(&self, url: &str, api_key: &str, body: &Value) -> Result<String, Self::Error>;
35}