KV GET/POST using curl?

1,813 views
Skip to first unread message

mic...@portworx.com

unread,
Sep 8, 2016, 1:48:44 PM9/8/16
to Consul
I'm trying to evaluate the K/V feature of consul as a replacement for etcd.  The doesn't seem to be a tool that will POST values to the KV store like etcdctl.  I can post via the web site, but we want do this from a program.  My boss want to demonstrate this with curl which, AFAICT, can't do POSTs.

Can anyone help me out here?

mic...@portworx.com

unread,
Sep 8, 2016, 2:43:21 PM9/8/16
to Consul
I found the answer.  Apparently, my googlefoo sucks from time to time.  This came right up when I searched for "consul curl KV pairs"

David Adams

unread,
Sep 13, 2016, 6:47:37 PM9/13/16
to consu...@googlegroups.com
Heh, actually that last line should be:
$ curl -Ss -XGET localhost:8500/v1/kv/test/hello |jq -r '.[].Value' |base64 -d

I was editing my actual commands to something simpler and missed that change.

Anyway, so this message is not entirely content-free, to clean up you use DELETE:

$ curl -XDELETE localhost:8500/v1/kv/test/hello
true

$ curl -iSs localhost:8500/v1/kv/test/hello
HTTP/1.1 404 Not Found
X-Consul-Index: 4831831
X-Consul-Knownleader: true
X-Consul-Lastcontact: 0
Date: Thu, 08 Sep 2016 18:19:49 GMT
Content-Length: 0
Content-Type: text/plain; charset=utf-8

(-i displays the headers, -XGET is implicit if there's no -d, -s silences any terminal feedback (eg when piping thru other commands, curl will print a progress bar by default), -S unsilences actual error messages)

On Thu, Sep 8, 2016 at 1:18 PM, David Adams <dave...@gmail.com> wrote:
curl can do POST. you just need to specify data to send with `-d "content goes here"`. Or you can be explicit about the verb with -X<verb>.

Altho, the write values to Consul, you need to use PUT, not POST:

$ curl -XPUT localhost:8500/v1/kv/test/hello -d "hello world"
true

$ curl -XGET localhost:8500/v1/kv/test/hello
[{"LockIndex":0,"Key":"test/hello","Flags":0,"Value":"aGVsbG8gd29ybGQ=","CreateIndex":4831750,"ModifyIndex":4831761}]

$ curl -Ss -XGET localhost:8500/v1/kv/shared/common/test |jq -r '.[].Value' |base64 -d
hello world



On Thu, Sep 8, 2016 at 12:48 PM, <mic...@portworx.com> wrote:
I'm trying to evaluate the K/V feature of consul as a replacement for etcd.  The doesn't seem to be a tool that will POST values to the KV store like etcdctl.  I can post via the web site, but we want do this from a program.  My boss want to demonstrate this with curl which, AFAICT, can't do POSTs.

Can anyone help me out here?

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/consul/issues
IRC: #consul on Freenode
---
You received this message because you are subscribed to the Google Groups "Consul" group.
To unsubscribe from this group and stop receiving emails from it, send an email to consul-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/consul-tool/fe236a9f-d14e-45b6-af48-e53c8c88128e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


David Adams

unread,
Sep 13, 2016, 6:47:37 PM9/13/16
to consu...@googlegroups.com
curl can do POST. you just need to specify data to send with `-d "content goes here"`. Or you can be explicit about the verb with -X<verb>.

Altho, the write values to Consul, you need to use PUT, not POST:

$ curl -XPUT localhost:8500/v1/kv/test/hello -d "hello world"
true

$ curl -XGET localhost:8500/v1/kv/test/hello
[{"LockIndex":0,"Key":"test/hello","Flags":0,"Value":"aGVsbG8gd29ybGQ=","CreateIndex":4831750,"ModifyIndex":4831761}]

$ curl -Ss -XGET localhost:8500/v1/kv/shared/common/test |jq -r '.[].Value' |base64 -d
hello world


On Thu, Sep 8, 2016 at 12:48 PM, <mic...@portworx.com> wrote:
I'm trying to evaluate the K/V feature of consul as a replacement for etcd.  The doesn't seem to be a tool that will POST values to the KV store like etcdctl.  I can post via the web site, but we want do this from a program.  My boss want to demonstrate this with curl which, AFAICT, can't do POSTs.

Can anyone help me out here?

--
Reply all
Reply to author
Forward
0 new messages