Skip to content

Dart implementation of key-value storage client for Hashicorp Consul

License

Notifications You must be signed in to change notification settings

semolex/consul-kv-dart

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

consul_kv_dart

Dart client for the Consul KV-store.

Wraps Consul's simple key/value store API.

Client uses HTTP requests to communicate with Consul.

Each method has optional parameters that are described in Consul API docs.

You might want to wrap responses into some kind of handler (check status codes, encode\convert values, etc.) - result is a flexible Response object.

Each method return Future which is used to get result.

Additional documentation can be found here.

Usage

A simple usage example:

Future main() async {
  var consul = new ConsulKV(port: 5579, defaultHeaders: {'X-Consul-Token': 'bcd1234'});
  var newKey = await consul.put('foo', 'bar');
  var foundKey = await consul.get('foo');
  var insertIfNotExists = await consul.put('foo', 'bar', cas: 1);
  var deleteKey = await consul.delete('foo');
  var keyNotExists = await consul.get('foo');

  print(newKey.body); // true
  print(newKey.statusCode); // 200

  print(foundKey.body); // [{"LockIndex":0,"Key":"foo","Value":"YmFy",
                        // "CreateIndex":208877,"ModifyIndex":208877}]
  print(foundKey.statusCode);  // 200

  print(insertIfNotExists.body); // false
  print(insertIfNotExists.statusCode); // 200

  print(deleteKey.body); // true
  print(deleteKey.statusCode); // 200

  print(keyNotExists.statusCode); // 404

  consul.close();

}

About

Dart implementation of key-value storage client for Hashicorp Consul

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages