Expand description
§Introduction
This Rust crate provides an easy-to-use interface to the Anytype API. At this stage of development, the code consists largely of builder structs that create a struct that can execute an Anytype API call.
WARNING!
This crate is still in development and therefore not stable nor efficient. Do not use it to write production code!
§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() {
// Create an any_type Vault object for the Anytype Desktop runnning on your computer
let vault = Vault::new(
"http://127.0.0.1:31009", "bye-bye-baby-baby-bye-bye-42",
);
// Execute the ListSpaces API call (multiple times if required) to list all spaces contained in the vault
let mut request = ListSpacesRequest::new().offset(0).limit(100);
'while_more: loop {
let response = request.send(&vault).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
The crate includes several binaries that illustrate how to use the library. The binaries can be compiled and run by executing the appropriate “cargo run –bin <binary_name>” command. The binaries assume that Anytype desktop is running and listening for API calls on the default port (i.e 31009).
§list_spaces binary
This binary simply prints a list of all the spaces in your vault.
§intro_step_1 binary
This program generates a new api_key by executing the CreateChallenge and CreateApiKey API calls.
§intro_step_2 binary
This program creates a new Anytype space by executing the CreateSpace API call. The program prompts you to enter the api_key generated by “intro_step_1” as well as a name for the space that will be created.
§intro_step_3 binary
This program creates the following:
- An Anytype Property called “Duck Testing” by executing a CreateProperty API call.
- Three Anytype Tags called “Basic”, “Intermediate” and “Advanced” using the CreateTag API call.
- An Anytype Type called “Ducks” by executing a CreateType API call.
This program prompts you to enter the api_key generated by “intro_step_1” as well as the id for the space that was created by “intro_step_2”.
The new “Ducks” type will have the “Duck Testing” property associated with it. However, you will have to edit the “Ducks” type to make the property visible for objects created with this type.
§intro_step_4 binary
This program creates 2 objects of the type “Ducks”. As before, the program will prompt you to enter the api_key generated by “intro_step_1” as well as the id for the space that was created by “intro_step_2”.
Once run you will see two new objects in the Anytype Desktop with the following titles:
- Welcome to alk_type!
- The future is bright, the future is Anytype!
§list_spaces
The code for this binary is similar to the example code listed above and will simply print out information relating to all the spaces that are defined in your local Anytype vault. As with the other binaries, you will be prompted to enter an api_key before it will run.
§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 library 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 vault: = Vault(server_url, api_key);
let request = GetProperty::new()
.space_id("byebyeverylongspaceidthathas.oddcharsinit")
.property_id("byethepropertyidcanalsobelong42")
.send(&vault);The “send” function will return either the desired object or a RequestFailure object.
§Current state of development
§Incomplete set of API calls
At this time the following API calls are either not working or not yet coded:
- Search objects accross all spaces (not working)
- Search for object within a space (not working)
- Add objects to list (not yet coded)
- Remove objects to list (not yet coded)
- Get list views (not yet coded)
- Get objects in list (not yet coded)
§Not optimized
Owing to the state of developement 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!
§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.
§License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
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.