Definitions:
path is a / separate string describing the node. Example /animals/dogs/german_shepard
Values are all strings
API:
get(path): String -> returns the value of a the node at the given path
set(path, value) -> changes the value of a given node to the new value. Should error out if the path does not currently exist
create(path, value) -> creates a new node and sets it to the given value. Should error out if the node already exists or if the node’s parent does not exist. That is /level1/level2 cannot be created if /level1 has not already been created
delete(path) -> deletes a node, but ONLY if it has no children
Follow up:
New API:
watch(path, callback_func) -> this allows a user to ‘watch’ a path and have a callback_function called whenever this node, or any child nodes are created/modified. The callback func should be of the form: fun callback(event: String, path: String, old_value: String?, new_value: String?).
Callbacks definition:
get operation # call with ('get', path, value, nil)
set operation # call with ('set', path, old_value, new_value)
create operation # call with ('create', path, nil, value)
delete operation # call with ('delete', path, value, nil)
Example: If we watch /animals/dogs than any time we change the value of /animals/dogs, or if we create any new sub nodes (ex: /animals/dogs/german_shepard or /animals/dogs/poodle/toy) we should call the callback function. The path passed in to the callback function should be the path of the node that was modified, NOT necessarily the path of the node that was watch’d (unless that happens to be the node modified). If a node is being created old_value is null, if a node is being deleted new_value is null.