kuon icon indicating copy to clipboard operation
kuon copied to clipboard

TODO: write documents of get, and post method

Open hppRC opened this issue 4 years ago • 0 comments

kuon::TwitterAPI::get is below

pub(crate) async fn get<T>(&self, endpoint: &str, params: &HashMap<&str, &str>) -> Result<T>
where
    T: DeserializeOwned,
{
    let header_bearer = format!("Bearer {}", self.bearer.access_token);

    let mut headers = HeaderMap::new();
    headers.insert(AUTHORIZATION, header_bearer.parse()?);

    let text = self
        .client
        .get(endpoint)
        .query(&params)
        .headers(headers)
        .send()
        .await?
        .text()
        .await?;

    let result = serde_json::from_str(&text)?;
    Ok(result)
}

This method sets query params in the URL. The OAuth1.1 needs query params to calculate the OAuth signature and set it in the request header. It's too boring to calculate with each request, so this method provides easy ways for developers to implement a custom API method.

The kuon::TwitterAPI::post method is the same.

hppRC avatar Jun 01 '20 04:06 hppRC