website: Document KV changes
This commit is contained in:
parent
2129b9d592
commit
9c5fca1a3e
|
@ -10,7 +10,7 @@ The main interface to Consul is a RESTful HTTP API. The API can be
|
|||
used for CRUD for nodes, services, checks, and configuration. The endpoints are
|
||||
versioned to enable changes without breaking backwards compatibility.
|
||||
|
||||
All endpoints fall into one of 6 categories:
|
||||
All endpoints fall into one of several categories:
|
||||
|
||||
* kv - Key/Value store
|
||||
* agent - Agent control
|
||||
|
@ -95,6 +95,8 @@ By default the datacenter of the agent is queried, however the dc can
|
|||
be provided using the "?dc=" query parameter. If a client wants to write
|
||||
to all Datacenters, one request per datacenter must be made.
|
||||
|
||||
### GET Method
|
||||
|
||||
When using the `GET` method, Consul will return the specified key,
|
||||
or if the "?recurse" query parameter is provided, it will return
|
||||
all keys with the given prefix.
|
||||
|
@ -105,9 +107,11 @@ Each object will look like:
|
|||
{
|
||||
"CreateIndex": 100,
|
||||
"ModifyIndex": 200,
|
||||
"LockIndex": 200,
|
||||
"Key": "zip",
|
||||
"Flags": 0,
|
||||
"Value": "dGVzdA=="
|
||||
"Value": "dGVzdA==",
|
||||
"Session": "adf4238a-882b-9ddc-4a9d-5b6758e4159e"
|
||||
}
|
||||
]
|
||||
|
||||
|
@ -117,37 +121,14 @@ that modified this key. This index corresponds to the `X-Consul-Index`
|
|||
header value that is returned. A blocking query can be used to wait for
|
||||
a value to change. If "?recurse" is used, the `X-Consul-Index` corresponds
|
||||
to the latest `ModifyIndex` and so a blocking query waits until any of the
|
||||
listed keys are updated. The multiple consistency modes can be used for
|
||||
`GET` requests as well.
|
||||
listed keys are updated. The `LockIndex` is the last index of a successful
|
||||
lock acquisition. If the lock is held, the `Session` key provides the
|
||||
session that owns the lock.
|
||||
|
||||
The `Key` is simply the full path of the entry. `Flags` are an opaque
|
||||
unsigned integer that can be attached to each entry. The use of this is
|
||||
left totally to the user. Lastly, the `Value` is a base64 key value.
|
||||
|
||||
If no entries are found, a 404 code is returned.
|
||||
|
||||
When using the `PUT` method, Consul expects the request body to be the
|
||||
value corresponding to the key. There are a number of parameters that can
|
||||
be used with a PUT request:
|
||||
|
||||
* ?flags=\<num\> : This can be used to specify an unsigned value between
|
||||
0 and 2^64-1. It is opaque to the user, but a client application may
|
||||
use it.
|
||||
|
||||
* ?cas=\<index\> : This flag is used to turn the `PUT` into a **Check-And-Set**
|
||||
operation. This is very useful as it allows clients to build more complex
|
||||
syncronization primitives on top. If the index is 0, then Consul will only
|
||||
put the key if it does not already exist. If the index is non-zero, then
|
||||
the key is only set if the index matches the `ModifyIndex` of that key.
|
||||
|
||||
The return value is simply either `true` or `false`. If the CAS check fails,
|
||||
then `false` will be returned.
|
||||
|
||||
Lastly, the `DELETE` method can be used to delete a single key or all
|
||||
keys sharing a prefix. If the "?recurse" query parameter is provided,
|
||||
then all keys with the prefix are deleted, otherwise only the specified
|
||||
key.
|
||||
|
||||
It is possible to also only list keys without any values by using the
|
||||
"?keys" query parameter along with a `GET` request. This will return
|
||||
a list of the keys under the given prefix. The optional "?separator="
|
||||
|
@ -164,6 +145,47 @@ For example, listing "/web/" with a "/" seperator may return:
|
|||
Using the key listing method may be suitable when you do not need
|
||||
the values or flags, or want to implement a key-space explorer.
|
||||
|
||||
If no entries are found, a 404 code is returned.
|
||||
|
||||
This endpoint supports blocking queries and all consistency modes.
|
||||
|
||||
### PUT method
|
||||
|
||||
When using the `PUT` method, Consul expects the request body to be the
|
||||
value corresponding to the key. There are a number of parameters that can
|
||||
be used with a PUT request:
|
||||
|
||||
* ?flags=\<num\> : This can be used to specify an unsigned value between
|
||||
0 and 2^64-1. It is opaque to the user, but a client application may
|
||||
use it.
|
||||
|
||||
* ?cas=\<index\> : This flag is used to turn the `PUT` into a Check-And-Set
|
||||
operation. This is very useful as it allows clients to build more complex
|
||||
syncronization primitives on top. If the index is 0, then Consul will only
|
||||
put the key if it does not already exist. If the index is non-zero, then
|
||||
the key is only set if the index matches the `ModifyIndex` of that key.
|
||||
|
||||
* ?acquire=\<session\> : This flag is used to turn the `PUT` into a lock acquisition
|
||||
operation. This is useful as it allows leader election to be built on top
|
||||
of Consul. If the lock is not held and the session is valid, this increments
|
||||
the `LockIndex` and sets the `Session` value of the key in addition to updating
|
||||
the key contents. A key does not need to exist to be acquired.
|
||||
|
||||
* ?release=\<session\> : This flag is used to turn the `PUT` into a lock release
|
||||
operation. This is useful when paired with "?acquire=" as it allows clients to
|
||||
yield a lock. This will leave the `LockIndex` unmodified but will clear the associated
|
||||
`Session` of the key. The key must be held by this session to be unlocked.
|
||||
|
||||
The return value is simply either `true` or `false`. If `false` is returned,
|
||||
then the update has not taken place.
|
||||
|
||||
### DELETE method
|
||||
|
||||
Lastly, the `DELETE` method can be used to delete a single key or all
|
||||
keys sharing a prefix. If the "?recurse" query parameter is provided,
|
||||
then all keys with the prefix are deleted, otherwise only the specified
|
||||
key.
|
||||
|
||||
## Agent
|
||||
|
||||
The Agent endpoints are used to interact with a local Consul agent. Usually,
|
||||
|
|
Loading…
Reference in New Issue