etcd_client 0.0.1-beta copy "etcd_client: ^0.0.1-beta" to clipboard
etcd_client: ^0.0.1-beta copied to clipboard

client for etcd db

markdown Copy code

etcd Dart Client #

A Dart package for interacting with etcd, a distributed key-value store.

Installation #

Add etcd_client to your pubspec.yaml:

dependencies:
  etcd_client:
    git:
      url: https://github.com/yourusername/etcd_client.git
      ref: main  # Replace with the branch or tag you want to use
Run dart pub get to fetch the package.

Usage
Import and initialize EtcdClient with your etcd server URL and optional credentials (username and password). Use the provided methods (put, get, update, delete) to interact with etcd.

dart
Copy code
import 'package:etcd_client/etcd_client.dart';

void main() async {
  final etcdUrl = 'http://localhost:2379'; // Replace with your etcd server URL
  final etcdClient = EtcdClient(
    etcdUrl: etcdUrl,
    username: 'your_username',
    password: 'your_password',
  );

  // Example of putting a key-value pair
  try {
    await etcdClient.put('/my/key', 'Hello, etcd!');
    print('Key-value pair added successfully.');
  } catch (e) {
    print('Failed to add key-value pair: $e');
  }

  // Example of getting a value for a key
  try {
    final value = await etcdClient.get('/my/key');
    print('Value for key /my/key: $value');
  } catch (e) {
    print('Failed to get value for key /my/key: $e');
  }

  // Example of updating a key-value pair
  try {
    await etcdClient.update('/my/key', 'Updated value');
    print('Key-value pair updated successfully.');
  } catch (e) {
    print('Failed to update key-value pair: $e');
  }

  // Example of deleting a key
  try {
    await etcdClient.delete('/my/key');
    print('Key deleted successfully.');
  } catch (e) {
    print('Failed to delete key: $e');
  }

  // Close the client when done
  etcdClient.close();
}
API Reference
EtcdClient class
Constructors
EtcdClient({String etcdUrl, String username, String password}): Creates a new etcd client instance.
Methods
Future<void> put(String key, String value): Stores a key-value pair in etcd.
Future<String> get(String key): Retrieves the value associated with a key from etcd.
Future<void> update(String key, String value): Updates the value for a key in etcd.
Future<void> delete(String key): Deletes a key from etcd.
void close(): Closes the HTTP client when done.
Notes
Replace your_username and your_password with your etcd credentials.
Ensure your etcd server URL (etcdUrl) is correct and accessible.
Handle errors and exceptions gracefully in your application.
Consider security best practices for handling credentials securely.
Contributing
Contributions are welcome! For major changes, please open an issue first to discuss what you would like to change.

License
This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments
Thank you to the Dart community and contributors who have helped improve this package.
0
likes
0
pub points
0%
popularity

Publisher

unverified uploader

client for etcd db

License

unknown (license)

Dependencies

http

More

Packages that depend on etcd_client