consul_kv_dart 1.0.2 copy "consul_kv_dart: ^1.0.2" to clipboard
consul_kv_dart: ^1.0.2 copied to clipboard

Dart 1 only

Implementation of key-value storage client for Hashicorp Consul

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.

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();

}
0
likes
40
pub points
0%
popularity

Publisher

unverified uploader

Implementation of key-value storage client for Hashicorp Consul

Homepage

License

MIT (LICENSE)

Dependencies

http

More

Packages that depend on consul_kv_dart