Examples
banshee/examples-collection/examples/api/
consul-key
Example: url.encode and base64.decode; the value of a key of Consul.
by banshee1 installation1 version
Published on October 27, 2026. First version in this collection.
A key of Consul
A key of the key/value store of Consul, read by its HTTP API: its name goes into the address, each part encoded; its value comes back in base64.
How to read it
url.encode($part): the text written to fit in an address, a blank as%20, a/as%2F. Each part of the name is encoded apart, and the/between them kept, since Consul reads them as levels.text.splitandtext.joincut the name and put it back together;list.addbuilds the list of the encoded parts.- Consul answers a list of one entry,
[{"Key": …, "Value": "b2Zm"}]:$entries[0]['Value']. base64.decodegives the text the base64 writes:b2Zmisoff. A text that is not base64 stops the collector, unreachable.
To adapt it
- A Consul with ACLs wants a token:
$token = need('protocol:http:token')andheaders=array('X-Consul-Token' => $token).