Bootstrap FreeKB - RabbitMQ - Create Virtual Host using the REST API
RabbitMQ - Create Virtual Host using the REST API

Updated:   |  RabbitMQ articles

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 Buy Me A Coffee



Comments


Add a Comment


Please enter 2be0f7 in the box below so that we can be sure you are a human.