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 neither 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 ListSpacesRequest;
use Vault;
async
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).
any_type_intro_1
This program generates a new api_key by executing the CreateChallenge and CreateApiKey API calls. The generated api_key is associated with the app_name of "any_test".
any_type_intro_2
This program creates a new Anytype space by executing the CreateSpace API call. The program prompts you to enter the api_key generated by "any_type_intro_1" as well as a name for the space that will be created.
any_type_intro_3
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 "any_type_intro_1" as well as the id for the space that was created by "any_type_intro_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.
any_type_intro_4
This program creates 2 objects of the type "Ducks". As before, the program will prompt you to enter the api_key generated by "any_type_intro_1" as well as the id for the space that was created by "any_type_intro_2".
Once run you will see two new objects in the Anytype Desktop with the following titles:
- Welcome to any_type!
- The future is bright, the future is Anytype!
any_type_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.
any_type_search
Runs a search using the contents of a file that is specified at run-time. The program also prompts you for an api_key and, optionally, a space-id to limit the space to a single space.
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 GetProperty;
...
let vault: = Vault;
let request = new
.space_id
.property_id
.send;
The "send" function will return either the desired object or a RequestFailure object.
Current state of development (v0.2.0)
Incomplete set of API calls
At this time the following API calls are not yet coded:
- Add objects to list
- Remove objects to list
- Get list views
- Get objects in list
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!
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.
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.