ConsulKv.Client (consul_kv v0.1.0)

The client for Consul KV store.

There are several configuration options for the client:

  • consul_recv_timeout (default: 5000) the timeout for receive response from the server side

  • consul_connect_timeout (default: 5000) the timeout for connect consul server

  • consul_kv_address the address of consul KV store

Link to this section Summary

Functions

Perform a DELETE request.

Perform a DELETE request.

Delete a single key or all keys sharing a prefix.

Perform a GET request.

Perform a GET request.

Return the specified key. If no key exists at the given path, a 404 is returned instead of a 200 response.

Perform a HEAD request.

Perform a HEAD request.

Perform a OPTIONS request.

Perform a OPTIONS request.

Perform a PATCH request.

Perform a PATCH request.

Perform a POST request.

Perform a POST request.

Perform a PUT request.

Perform a PUT request.

This interface updates the value of the specified key. If no key exists at the given path, the key will be created.

Perform request and raise in case of error.

Perform a TRACE request.

Perform a TRACE request.

Link to this section Types

Specs

option() ::
  {:method, Tesla.Env.method()}
  | {:url, Tesla.Env.url()}
  | {:query, Tesla.Env.query()}
  | {:headers, Tesla.Env.headers()}
  | {:body, Tesla.Env.body()}
  | {:opts, Tesla.Env.opts()}

Link to this section Functions

Link to this function

delete(client, url, opts)

Specs

Perform a DELETE request.

See request/1 or request/2 for options definition.

delete("/users")
delete("/users", query: [scope: "admin"])
delete(client, "/users")
delete(client, "/users", query: [scope: "admin"])
delete(client, "/users", body: %{name: "Jon"})
Link to this function

delete!(client, url, opts)

Specs

Perform a DELETE request.

See request!/1 or request!/2 for options definition.

delete!("/users")
delete!("/users", query: [scope: "admin"])
delete!(client, "/users")
delete!(client, "/users", query: [scope: "admin"])
delete!(client, "/users", body: %{name: "Jon"})
Link to this function

delete_kv(key, query_params \\ [])

Specs

delete_kv(String.t(), Keyword.t()) :: {:ok, true} | {:error, any()}

Delete a single key or all keys sharing a prefix.

The key should be a string, the query parameters could be Keyword:

  • dc (default: "") Specifies the datacenter.

  • recurse (default: false) Specifies to delete all keys which have the specified prefix. Without this, only a key with an extract match will be deleted.

  • cas (default: 0) Specifies to use a Check-And-Set operation

  • ns (default: "") Specifies the namespace to query.

Link to this function

get(client, url, opts)

Specs

Perform a GET request.

See request/1 or request/2 for options definition.

get("/users")
get("/users", query: [scope: "admin"])
get(client, "/users")
get(client, "/users", query: [scope: "admin"])
get(client, "/users", body: %{name: "Jon"})
Link to this function

get!(client, url, opts)

Specs

Perform a GET request.

See request!/1 or request!/2 for options definition.

get!("/users")
get!("/users", query: [scope: "admin"])
get!(client, "/users")
get!(client, "/users", query: [scope: "admin"])
get!(client, "/users", body: %{name: "Jon"})
Link to this function

get_kv(key, query_params \\ [])

Specs

get_kv(String.t(), Keyword.t()) :: {:ok, [ConsulKv.t()]} | {:error, any()}

Return the specified key. If no key exists at the given path, a 404 is returned instead of a 200 response.

The key should be a string, the query parameters could be Keyword:

  • dc (default: "") Specifies the datacenter.

  • recurse (default: false) Specifies to delete all keys which have the specified prefix. Without this, only a key with an extract match will be deleted.

  • raw (default: false) Specifies the response is just the raw value of the key, without any encoding or metadata.

  • keys (default: false) Specifies to return only keys (no values or metadata).

  • separator (default: "") Specifies the string to use as a separator for recursive key lookups.

  • ns (default: "") Specifies the namespace to query.

Link to this function

head(client, url, opts)

Specs

Perform a HEAD request.

See request/1 or request/2 for options definition.

head("/users")
head("/users", query: [scope: "admin"])
head(client, "/users")
head(client, "/users", query: [scope: "admin"])
head(client, "/users", body: %{name: "Jon"})
Link to this function

head!(client, url, opts)

Specs

Perform a HEAD request.

See request!/1 or request!/2 for options definition.

head!("/users")
head!("/users", query: [scope: "admin"])
head!(client, "/users")
head!(client, "/users", query: [scope: "admin"])
head!(client, "/users", body: %{name: "Jon"})
Link to this function

options(client, url, opts)

Specs

Perform a OPTIONS request.

See request/1 or request/2 for options definition.

options("/users")
options("/users", query: [scope: "admin"])
options(client, "/users")
options(client, "/users", query: [scope: "admin"])
options(client, "/users", body: %{name: "Jon"})
Link to this function

options!(client, url, opts)

Specs

Perform a OPTIONS request.

See request!/1 or request!/2 for options definition.

options!("/users")
options!("/users", query: [scope: "admin"])
options!(client, "/users")
options!(client, "/users", query: [scope: "admin"])
options!(client, "/users", body: %{name: "Jon"})
Link to this function

patch(client, url, body, opts)

Specs

Perform a PATCH request.

See request/1 or request/2 for options definition.

patch("/users", %{name: "Jon"})
patch("/users", %{name: "Jon"}, query: [scope: "admin"])
patch(client, "/users", %{name: "Jon"})
patch(client, "/users", %{name: "Jon"}, query: [scope: "admin"])
Link to this function

patch!(client, url, body, opts)

Specs

Perform a PATCH request.

See request!/1 or request!/2 for options definition.

patch!("/users", %{name: "Jon"})
patch!("/users", %{name: "Jon"}, query: [scope: "admin"])
patch!(client, "/users", %{name: "Jon"})
patch!(client, "/users", %{name: "Jon"}, query: [scope: "admin"])
Link to this function

post(client, url, body, opts)

Specs

Perform a POST request.

See request/1 or request/2 for options definition.

post("/users", %{name: "Jon"})
post("/users", %{name: "Jon"}, query: [scope: "admin"])
post(client, "/users", %{name: "Jon"})
post(client, "/users", %{name: "Jon"}, query: [scope: "admin"])
Link to this function

post!(client, url, body, opts)

Specs

Perform a POST request.

See request!/1 or request!/2 for options definition.

post!("/users", %{name: "Jon"})
post!("/users", %{name: "Jon"}, query: [scope: "admin"])
post!(client, "/users", %{name: "Jon"})
post!(client, "/users", %{name: "Jon"}, query: [scope: "admin"])
Link to this function

put(client, url, body, opts)

Specs

Perform a PUT request.

See request/1 or request/2 for options definition.

put("/users", %{name: "Jon"})
put("/users", %{name: "Jon"}, query: [scope: "admin"])
put(client, "/users", %{name: "Jon"})
put(client, "/users", %{name: "Jon"}, query: [scope: "admin"])
Link to this function

put!(client, url, body, opts)

Specs

Perform a PUT request.

See request!/1 or request!/2 for options definition.

put!("/users", %{name: "Jon"})
put!("/users", %{name: "Jon"}, query: [scope: "admin"])
put!(client, "/users", %{name: "Jon"})
put!(client, "/users", %{name: "Jon"}, query: [scope: "admin"])
Link to this function

put_kv(key, value, query_params \\ [])

Specs

put_kv(String.t(), any(), Keyword.t()) :: {:ok, true} | {:error, any()}

This interface updates the value of the specified key. If no key exists at the given path, the key will be created.

The key should be a string, and value could be a string or any types which could be encode to json. The query parameters could be Keyword:

  • dc (default: "") Specifies the datacenter.

  • flags (default: 0) Specifies an unsigned value between 0 and (2^64)-1.

  • cas (default: 0) Specifies to use a Check-And-Set operation. If the index is 0, Consul will only put the key if it does not already exist. If the index is non-zero, the key is only set if the index matches the ModifyIndex of that key.

  • acquire (default: "") Supply a session ID to use in a lock acquisition operation. This is useful as it allows leader election to be built on top of Consul.

  • release (default: "") Supply a session ID to use in a release operation.

  • ns (default: "") Specifies the namespace to query.

Link to this function

request(client \\ %Tesla.Client{}, options)

Specs

Perform a request.

Options

  • :method - the request method, one of [:head, :get, :delete, :trace, :options, :post, :put, :patch]
  • :url - either full url e.g. "http://example.com/some/path" or just "/some/path" if using Tesla.Middleware.BaseUrl
  • :query - a keyword list of query params, e.g. [page: 1, per_page: 100]
  • :headers - a keyworld list of headers, e.g. [{"content-type", "text/plain"}]
  • :body - depends on used middleware:
    • by default it can be a binary
    • if using e.g. JSON encoding middleware it can be a nested map
    • if adapter supports it it can be a Stream with any of the above
  • :opts - custom, per-request middleware or adapter options

Examples

ExampleApi.request(method: :get, url: "/users/path")

# use shortcut methods
ExampleApi.get("/users/1")
ExampleApi.post(client, "/users", %{name: "Jon"})
Link to this function

request!(client \\ %Tesla.Client{}, options)

Specs

request!(Tesla.Env.client(), [option()]) :: Tesla.Env.t() | no_return()

Perform request and raise in case of error.

This is similar to request/2 behaviour from Tesla 0.x

See request/2 for list of available options.

Link to this function

trace(client, url, opts)

Specs

Perform a TRACE request.

See request/1 or request/2 for options definition.

trace("/users")
trace("/users", query: [scope: "admin"])
trace(client, "/users")
trace(client, "/users", query: [scope: "admin"])
trace(client, "/users", body: %{name: "Jon"})
Link to this function

trace!(client, url, opts)

Specs

Perform a TRACE request.

See request!/1 or request!/2 for options definition.

trace!("/users")
trace!("/users", query: [scope: "admin"])
trace!(client, "/users")
trace!(client, "/users", query: [scope: "admin"])
trace!(client, "/users", body: %{name: "Jon"})