
This assumes you have created a RabbitMQ user with the administrator tag.
Refer to the RabbitMQ REST API documentation.
The curl command with the --user option can be used to make an API connection to RabbitMQ. In this example, John Doe will make a connection to the RabbitMQ server listening on port 15671 and create a virtual host named "foo".
curl
--request PUT
--user john.doe:itsasecret
--header 'content-type: application/json'
--url http://hostname:15671/api/vhosts/foo
--write-out "%{http_code}"
Optionally, the virtual host can be given a description. It is noteworthy that the description will not be shown in the RabbitMQ web browser GUI, or when using the rabbitmqctl command. However, when listing virtual hosts using the REST API, the description will be included in the output.
curl
--request PUT
--user john.doe:itsasecret
--header 'content-type: application/json'
--url http://hostname:15671/api/vhosts/foo
--data '{ "description": "example description" }'
--write-out "%{http_code}"
No output will be returned, regardless if the virtual host is or is not created. For this reason, the -w or --write-out option is included to get the return code of the curl command.
Did you find this article helpful?
If so, consider buying me a coffee over at