HTTP API
Everything you need to know to work with the VerneMQ HTTP administration interface
The VerneMQ HTTP API is enabled by default and installs an HTTP handler on http://localhost:8888/api/v1
. To read more about configuring the HTTP listener, see HTTP Listener Configuration. You can configure a HTTP listener, or a HTTPS listener to serve the HTTP API v1.
Managing API keys
The VerneMQ HTTP API uses basic authentication where an API key is passed as the username and the password is left empty, as an alternative the x-api-key header option can be used. API keys have a scope and (optional) can have an expiry date. So the first step to us the HTTP API is to create an API key.
Scopes
Each HTTP Module can be protected by an API key. An API key can be limited to a certain http module or further restrict some functionality within the http module. The scope used by the management API is "mgmt". Currently, the following scopes are supported "status", "mgmt", "metrics", "health".
Create API key
or with scope and an expiry date (in local time)
The keys are persisted and available on all cluster nodes.
List API keys
To list existing keys do:
Add API key
To add an API key of your own choosing, do:
Delete API key
To delete an API key do:
Advanced Settings (key rotation, key complexity)
You can specifiy the minimal length of an API key (default: 0) in vernemq.conf
or a set a max duration of an API key before it expires (default: undefined)
Please note that changing those settings after some api keys have already been created has no influence on already created keys.
You can enable or disable API key authentication per module, or per module per listener.
Possible modules are vmq_metrics_http,vmq_http_mgmt_api, vmq_status_http, vmq_health_http. Possible values for auth.mode are noauth or apikey.
API usage
The VerneMQ HTTP API is a wrapper over the vmq-admin
CLI tool, and anything that can be done using vmq-admin
can be done using the HTTP API. Note that the HTTP API is therefore subject to any changes made to the vmq-admin
tools and their flags & options structure. All requests are performed doing a HTTP GET and if no errors occurred an HTTP 200 OK code is returned with a possible non-empty JSON payload.
The API is using basic auth where the API key is passed as the username. An example using curl
would look like this:
The mapping between vmq-admin
and the HTTP API is straightforward, and if one is already familiar with how the vmq-admin
tool works, working with the API should be easy. The mapping works such that the command part of a vmq-admin
invocation is turned into a path, and the options and flags are turned into the query string.
A mandatory parameter like the client-id
in the vmq-admin session disconnect client-id=myclient
command should be translated as: ?client-id=myclient
.
An optional flag like --cleanup
in the vmq-admin session disconnect client-id=myclient --cleanup
command should be translated as: &--cleanup
Let's look at the cluster join command as an example, which looks like this:
This turns into a GET request:
To test, run it with curl
:
And the returned response would look like:
Below are some other examples.
Get cluster status information
Request:
Curl:
Response:
Retrieve session information
Request:
Curl:
Response:
List all installed listeners
Request:
Curl:
Response:
Retrieve plugin information
Request:
Curl:
Response:
Set configuration values
Request:
Curl:
Response:
Disconnect a client
Request:
Curl:
Response:
Last updated