CRUD Operations
How to do basic CRUD operations on an atServer
In Dart, the AtClient is stored within the AtClientManager. Once an atSign has been onboarded, you will be able to access the AtClientManager for its associated atSign.
AtClientManager
AtClientManager is a singleton model. When AtClientManager.getInstance() is called, it will get the AtClientManager instance for the last onboarded atSign.
AtClientManager atClientManager = AtClientManager.getInstance();AtClient
As previously mentioned, the AtClientManager stores the actual AtClient itself. You can retrieve the AtClient by calling atClientManager.atClient.
AtClient atClient = atClientManager.atClient;atKey
Before you can do anything with an atRecord, you need an atKey to represent it.
If you don't know how to create an atKey, please see the reference first.
Creating / Updating Data
To create data the put method is used, this method accepts text (String) or binary (List<int>).
Strongly Typed Methods
Since put accepts both String or List<int> as a value, the typing is dynamic. atClient also contains the strongly typed putText which only accepts String for the value, or putBinary which only accepts List<int> for the value.
To update existing data
Updating existing data is done by doing a put to the same atKey, this will overwrite any existing data stored in the atRecord.
The bytes [1, 2, 3, 4] have now replaced the string "123-456-7890".
Reading Data
There are two parts to reading data using the atClient SDK:
Scanning for and listing out the atKeys for atRecords that can be retrieved
Retrieving the atRecord for a given atKey
1. Scanning and listing atKeys
There are two methods available for scanning and listing atKeys:
getAtKeyswhich provides the list in Class format (i.e.List<AtKey>)getKeyswhich provides the list in String format (i.e.List<String>)
Both methods accept the same parameters, only the return type is different. So we will show the more commonly used getAtKeys signature:
regex
A regular expression used to filter the list of atKeys.
sharedBy
Filter the list of atKeys to only include ones shared by a particular atSign.
sharedWith
Filter the list of atKeys to only include ones shared with a particular atSign.
showHiddenKeys
A boolean flag to enable the inclusion of hidden atKeys (default = false)
Usage
Get all available (non-hidden) atKeys:
All atKeys which end with ".wavi" in the record identifier part:
2. Retrieving atRecords by atKey
To retrieve an atRecord, you must know the atKey and pass it to the get method.
Calling this function will return an AtValue, and update the atKey passed to it with any changes to the metadata.
Usage
Deleting Data
To delete data, simply call the delete method with the atKey for the atRecord to delete.
Usage
Additional Features
See Additional Features to learn about synchronization, which supports syncing of a local atServer, allowing CRUD operations to work even if the application has no internet access.
API Docs
You can find the API reference for the entire package available on pub.
The AtClient class API reference is available here.
C
You can find all of these examples on our GitHub.
Table of Contents
Introduction
In this section, we will learn how to put, get, and delete an atKey.
If you are unfamiliar with the different atKey types, check out our documentation on atRecords.
Put Public atKey
1. Create Public AtKey
First, create a public atKey. It is important to note that the shared_by atSign should be the same as the authenticated atSign in the application.
2. Call `atclient_put_public_key`
Next, simply *put* the value into your atServer. Since we are putting a public value into our atServer, no data will be encrypted and this data will be available for any atSign to get.
We will pass NULL into the request_options and commit_id parameters because we want to use the default options for now and we don't particularly care about the commit_id that it returns, but you could receive it if you would like.
This function returns an int for error handling, in which a non-zero exit code indicates an error.
Example Application
Put Self atKey
1. Create a Self atKey
2. Call `atclient_put_self_key`
This will put a value specially encrypted for your atServer that only the atSign's atKeys can decrypt.
We will pass NULL into the request_options and commit_id parameters because we want to use the default options for now and we don't particularly care about the commit_id that it returns, but you could receive it if you would like.
This function will return an int for error handling, in which a non-zero exit code indicates an error.
Example Application
Put Shared atKey
1. Create a Shared atKey
2. Call `atclient_put_shared_key`
This function will put our string value into the atServer. Since we are using a Shared atKey, that means only the shared_by and shared_with atSign will be able to decrypt this value.
We will pass NULL into the request_options and commit_id parameters because we want to use the default options for now and we don't particularly care about the commit_id that it returns, but you could receive it if you would like.
This function returns an int for error handling, in which a non-zero exit code indicates an error.
Example Application
Get Public atKey
1. Create Public AtKey
First, create a public atKey. It is important to note that the shared_by atSign should be the same as the authenticated atSign in the application.
2. Call `atclient_get_public_key`
We will create a variable named value and pass the address to it in our atclient_get_public_key function call. The function will allocate memory for us and populate that variable for us.
We will pass NULL into the request_options parameter because we want to use the default options for now.
This function returns an int for error handling, in which a non-zero exit code indicates an error.
3. Free `value`
Once we are done with the value itself, we should free it to avoid any memory leaks.
Example Application
Get Self atKey
1. Create a Self atKey
2. Call `atclient_get_self_key`
We will create a variable named value and pass the address to it in our atclient_get_self_key function call. The function will allocate memory for us and populate that variable for us.
We will pass NULL into the request_options parameter because we want to use the default options for now.
This function returns an int for error handling, in which a non-zero exit code indicates an error.
3. Free `value`
Once we are done with the value itself, we should free it to avoid any memory leaks.
Example Application
Get Shared atKey
1. Create a Shared atKey
2. Call `atclient_get_shared_key`
We will create a variable named value and pass the address to it in our atclient_get_shared_key function call. The function will allocate memory for us and populate that variable for us.
We will pass NULL into the request_options parameter because we want to use the default options for now.
This function returns an int for error handling, in which a non-zero exit code indicates an error.
3. Free `value`
Once we are done with the value itself, we should free it to avoid any memory leaks.
Example Application
Delete an atKey
1. Create an AtKey
First step is to create the atKey that you wish to delete. This can be of any atKey type (public, self, or shared). What is important to note is that you can only delete an atKey that you own (which means that the authenticated atSign is the same as the shared_by atSign). This should be obvious because you can only delete atKeys that have once been created by you. Only the rightful owners of the atKey that was created can delete it.
For the sake of this demo, we will create a Shared atKey.
2. Call `atclient_delete`
atclient_delete will delete the atKey from your atServer.
We will pass NULL to the request_options and commit_id parameter because we want to use the default options for now and we do not care about the commit_id. You can receive the commit_id if you would like by passing an int pointer.
It is pointless to set any metadata to the atKey when deleting. Metadata is only useful when getting (you can read any metadata that the key possesses) and putting (you can modify the atKey's behavior). When you are deleting, no metadata is used.
This functions returns an int for error handling. A non-zero exit code indicates an error.
Example Application
Request Options
Last updated

