Skip to main content
In this hands-on tutorial, you’ll learn how to manage key/value pairs in HashiCorp Consul’s K/V store using three methods: the web UI, the CLI, and the HTTP API. We’ll cover adding, querying, and deleting entries, plus best practices for decoding API responses.

1. Prerequisites

When you first open the UI, the Key/Value section should be empty.

2. Adding Data via the CLI

Use the consul kv put command to insert entries under the apps/eCommerce prefix.
Each command will return a confirmation similar to:

3. Deleting an Entry

If you need to remove a key, use consul kv delete. For example, to delete the connection string:
Successful deletion yields:

4. Adding Data for the Search Service

Next, create configuration entries for a hypothetical search service:
Refresh the UI to verify new keys under apps → search.
If you don’t see the new entries right away, click the Refresh button in the UI or clear your browser cache.

5. Querying Data in the CLI

Retrieve a value directly from the CLI:
Output:

6. Querying Data via the HTTP API

Consul’s HTTP API returns values in Base64. First, inspect the raw JSON:
Sample response:
To decode in one step:
Output:
Any application using Consul’s K/V HTTP API must Base64-decode the Value field before use.

7. Operation Summary


8. Further Reading

You’ve now mastered adding, deleting, and retrieving key/value pairs in Consul using the UI, CLI, and HTTP API. Happy configuring!

Watch Video

Practice Lab