Crate vkclient

source ·
Expand description

Base VK API client realisation.

This client supports zstd compression and msgpack format of VK API. It’s works with http2 only connections.

Usage

use vkclient::{List, VkApi, VkApiError};
let client: VkApi = vkclient::VkApiBuilder::new(access_token).into();

async {
    let users = get_users_info(&client).await.unwrap();
}

async fn get_users_info(client: &VkApi) -> Result<Vec<UsersGetResponse>, VkApiError> {
    client.send_request("users.get", UsersGetRequest {
        user_ids: List(vec![1,2]),
        fields: List(vec!["id", "sex"]),
   }).await
}

#[derive(Serialize)]
struct UsersGetRequest<'a> {
    user_ids: List<Vec<usize>>,
    fields: List<Vec<&'a str>>,
}

#[derive(Deserialize)]
struct UsersGetResponse {
    id: i64,
    first_name: String,
    last_name: String,
    sex: u8,
}

Features

  • compression_zstd - enabled by default. Adds zstd compression support;
  • compression_gzip - enabled by default. Adds gzip compression support;
  • encode_json - enabled by default. Adds json encoding support;
  • encode_msgpack - enabled by default. Adds msgpack encoding support;

Modules

Structs

Vk API List helper Serialize any iterable struct with ToString items to string separated by comma. Example:
Client for long poll subscriptions
Long poll request structure.
Long poll events chunk. You should to replace ts on next request with this value.
Major and minor versions of VK API
Base VK API client realisation.
API Client builder struct. Use VkApi::from or into to make VkApi struct.
VK Backend business logic errors. More info about codes.

Enums

Vk Api errors. VkApiError::Vk - is an error of buisness logic, like expired token or incorrect request params Other errors is about things around your request, like a serialization/deserialization or network errors.

Traits

API method description