Skip to main content

Crate any_type

Crate any_type 

Source
Expand description

§Introduction

This Rust crate provides an easy-to-use async interface to the Anytype API. At this stage of development, the code consists largely of builder structs that setup and execute an Anytype API call.

WARNING!

This crate is still in development and therefore subject to change and not yet optimized nor fully tested.

§Example of how to use the crate

The code shown below will, once it is modified to use a ‘real’ api_key, list all the spaces contained in the Anytype vault

use any_type::spaces::ListSpacesRequest;
use any_type::vault::Vault;

#[tokio::main]
async fn main() {
        let api_key = "bye-bye-baby-baby-bye-bye-42";
        let server = "http://127.0.0.1:31009";
    // Execute the ListSpaces API call (multiple times if required) to list all spaces contained in the vault
    let mut request = ListSpacesRequest::new(api_key, server).offset(0).limit(100);
    'while_more: loop {
        let response = request.send().await;
        let list_of = response.unwrap();  // Don't do this in production code!  Remember Cloudflare!
        for s in list_of.spaces.iter() {
            println!("name        : {}", s.name);
            println!("description : {}", s.description);
            println!("gateway url : {}", s.gateway_url);
            println!("id          : {}", s.id);
            println!("network id  : {}", s.network_id);
            println!("object      : {}", s.object);
            println!("");
        }
        if !list_of.has_more {
            break 'while_more;
        }
        request = request.offset(list_of.next_offset);
    }
}

§Getting started

Example code is provided in the any_type_examples repository. The code contained in that repository is intended to be used as a starting point for developing applications that use the any_type crate. The code illustrates the following elements of the Anytype API:

  • How to generate an api key
  • How to create a space
  • How to create a type
  • How to create a property
  • How to create a tag
  • How to create an object of a type
  • How to search Anytype spaces

§Important library features

§Limited abstraction

The library creates a very thin layer of abstraction for the Anytype API. The goal is to develop the crate in-step with the development of the Anytype API. For example, since there are currently no Chat related API calls, this library does not provide functions that allow for working with a chat channel.

§Builder structs

The any_type library crate provide access to Anytypes objects via objects created by builder structs. This results in code that looks like this:

use any_type::properties::GetProperty;

let request = GetProperty::new("my_api_key_is_quite_long", "http://127.0.0.1:31009")
    .space_id("byebyeverylongspaceidthathas.oddcharsinit") 
    .property_id("byethepropertyidcanalsobelong42")
    .send();

The “send” function will return either the desired object or a RequestFailure object.

§Several enum types to simplify defining Anytype values

The Anytype API requires the programmer to use string literals to define a number of API parameters. In order to make life easier for the application programmer, a set of enums have been created to make this easier:

  • The “PropertyFormat” enum defines values for the various property formats (e.g. checkbox, select, multi_select, etc)
  • The “AnytypeColor” enum defines values for the colors that icons and tags can have(e.g grey, yellow, orange, etc)
  • The “IconName” enum defines values for various “named” icons that can be defined (e.g airplane, bluetooth radio, etc)

§Current state of development (v0.5.0)

§Complete set of API calls

All the API calls documented on the Antype website have now been implemented.

§Not optimized

Owing to the state of development of the Anytype API (i.e. subject to change), the code has not been written to be efficient. The focus has been on developing a library that is easy for the user (i.e. software developer) to use.

§Incomplete documentation

Some of the elements of the library have been documented, but there is still work to be done!

§Limited Testing

Testing is being conducted every day, but there is still some way to go! However, at this stage at the very least the intro binaries should work on all systems. If this is not the case, the author would be very happy to receive any feedback you may have via email.

§Known Bugs (i.e. no fix)

  • GetTemplateRequest will fail if no template-id is provided
    • Not fixed because this is an Anytype API error that should be fixed by the Anytype API developers

§License

Licensed under either of

at your option.

§Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Modules§

api
auth
config
icons
lists
members
node
objects
properties
search
spaces
tags
templates
types