Search code examples
apiconsul

Single API to list all the services - consul cluster


Is there a single API to list all the services registered in a consul cluster?

Constraint: ui is disabled.


Solution

  • That depends, whether you have a single datacenter or no. If yes, then you can use a Consul HTTP API to query all the services in current agent's datacenter. Otherwise you will need to query all the datacenter names first and then query services for exact datacenter.

    Here is some example from the documentation:

    Simple request

    curl https://consul.rocks/v1/catalog/services
    

    will return the services registered in a given datacenter as follows:

    {
      "consul": [],
      "redis": [],
      "postgresql": [
        "primary",
        "secondary"
      ]
    }