2015-01-18 00:28:53 +00:00
---
layout: "docs"
page_title: "Catalog (HTTP)"
sidebar_current: "docs-agent-http-catalog"
description: >
The Catalog is the endpoint used to register and deregister nodes,
2015-02-08 17:44:36 +00:00
services, and checks. It also provides query endpoints.
2015-01-18 00:28:53 +00:00
---
# Catalog HTTP Endpoint
The Catalog is the endpoint used to register and deregister nodes,
2015-02-08 17:44:36 +00:00
services, and checks. It also provides query endpoints.
2015-01-18 00:28:53 +00:00
The following endpoints are supported:
* [`/v1/catalog/register` ](#catalog_register ) : Registers a new node, service, or check
* [`/v1/catalog/deregister` ](#catalog_deregister ) : Deregisters a node, service, or check
* [`/v1/catalog/datacenters` ](#catalog_datacenters ) : Lists known datacenters
* [`/v1/catalog/nodes` ](#catalog_nodes ) : Lists nodes in a given DC
* [`/v1/catalog/services` ](#catalog_services ) : Lists services in a given DC
* [`/v1/catalog/service/<service>` ](#catalog_service ) : Lists the nodes in a given service
2016-05-27 07:12:17 +00:00
* [`/v1/catalog/node/<node>` ](#catalog_node ) : Lists the services provided by a node
2015-01-18 00:28:53 +00:00
2015-02-08 17:44:36 +00:00
The `nodes` and `services` endpoints support blocking queries and
tunable consistency modes.
2015-01-18 00:28:53 +00:00
### <a name="catalog_register"></a> /v1/catalog/register
2015-02-08 17:44:36 +00:00
The register endpoint is a low-level mechanism for registering or updating
2016-11-25 16:00:02 +00:00
entries in the catalog. It is usually preferable to instead use the
2015-03-04 15:22:53 +00:00
[agent endpoints ](agent.html ) for registration as they are simpler and perform
[anti-entropy ](/docs/internals/anti-entropy.html ).
2015-01-18 00:28:53 +00:00
2016-11-25 16:00:02 +00:00
The register endpoint expects a JSON request body to be `PUT` . The request
2015-02-08 17:44:36 +00:00
body must look something like:
2015-01-18 00:28:53 +00:00
```javascript
{
"Datacenter": "dc1",
"Node": "foobar",
"Address": "192.168.10.10",
2016-07-19 17:55:46 +00:00
"TaggedAddresses": {
2016-08-16 17:49:03 +00:00
"lan": "192.168.10.10",
"wan": "10.0.10.10"
2016-07-19 17:55:46 +00:00
},
2017-01-11 23:44:13 +00:00
"NodeMeta": {
"somekey": "somevalue"
},
2015-01-18 00:28:53 +00:00
"Service": {
"ID": "redis1",
"Service": "redis",
"Tags": [
2016-11-25 16:00:02 +00:00
"primary",
2015-01-18 00:28:53 +00:00
"v1"
],
"Address": "127.0.0.1",
"Port": 8000
},
"Check": {
"Node": "foobar",
"CheckID": "service:redis1",
"Name": "Redis health check",
"Notes": "Script based health check",
"Status": "passing",
"ServiceID": "redis1"
}
}
```
The behavior of the endpoint depends on what keys are provided. The endpoint
2015-02-08 17:44:36 +00:00
requires `Node` and `Address` to be provided while `Datacenter` will be defaulted
2015-01-18 00:28:53 +00:00
to match that of the agent. If only those are provided, the endpoint will register
2016-02-07 18:56:47 +00:00
the node with the catalog. `TaggedAddresses` can be used in conjunction with the
[`translate_wan_addrs` ](/docs/agent/options.html#translate_wan_addrs ) configuration
2016-11-25 16:00:02 +00:00
option and the `wan` address. The `lan` address was added in Consul 0.7 to help find
2016-08-16 17:49:03 +00:00
the LAN address if address translation is enabled.
2015-01-18 00:28:53 +00:00
2017-01-11 23:44:13 +00:00
The `Meta` block was added in Consul 0.7.3 to enable associating arbitrary metadata
key/value pairs with a node for filtering purposes. For more information on node metadata,
see the [node meta ](/docs/agent/options.html#_node_meta ) section of the configuration page.
2015-02-08 17:44:36 +00:00
If the `Service` key is provided, the service will also be registered. If
`ID` is not provided, it will be defaulted to the value of the `Service.Service` property.
Only one service with a given `ID` may be present per node. The service `Tags` , `Address` ,
and `Port` fields are all optional.
2016-11-25 16:00:02 +00:00
If the `Check` key is provided, a health check will also be registered. The register API manipulates the health check entry in the Catalog, but it does not setup
2015-02-08 17:44:36 +00:00
the script, TTL, or HTTP check to monitor the node's health. To truly enable a new
health check, the check must either be provided in agent configuration or set via
the [agent endpoint ](agent.html ).
The `CheckID` can be omitted and will default to the value of `Name` . As with `Service.ID` ,
the `CheckID` must be unique on this node. `Notes` is an opaque field that is meant to
hold human-readable text. If a `ServiceID` is provided that matches the `ID`
of a service on that node, the check is treated as a service level health
2016-09-21 13:50:12 +00:00
check, instead of a node level health check. The `Status` must be one of `passing` , `warning` , or `critical` .
2015-01-18 00:28:53 +00:00
2016-07-19 17:55:46 +00:00
Multiple checks can be provided by replacing `Check` with `Checks` and sending
an array of `Check` objects.
2015-01-18 00:28:53 +00:00
It is important to note that `Check` does not have to be provided with `Service`
2015-02-08 17:44:36 +00:00
and vice versa. A catalog entry can have either, neither, or both.
2015-01-18 00:28:53 +00:00
2015-06-15 18:45:08 +00:00
An optional ACL token may be provided to perform the registration by including a
`WriteRequest` block in the query payload, like this:
```javascript
{
"WriteRequest": {
"Token": "foo"
}
}
```
2015-02-08 17:44:36 +00:00
If the API call succeeds, a 200 status code is returned.
2015-01-18 00:28:53 +00:00
### <a name="catalog_deregister"></a> /v1/catalog/deregister
2015-02-08 17:44:36 +00:00
The deregister endpoint is a low-level mechanism for directly removing
2016-11-25 16:00:02 +00:00
entries from the Catalog. It is usually preferable to instead use the
2015-03-04 15:22:53 +00:00
[agent endpoints ](agent.html ) for deregistration as they are simpler and perform
[anti-entropy ](/docs/internals/anti-entropy.html ).
2015-01-18 00:28:53 +00:00
2016-11-25 16:00:02 +00:00
The deregister endpoint expects a JSON request body to be `PUT` . The request
2015-01-18 00:28:53 +00:00
body must look like one of the following:
```javascript
{
"Datacenter": "dc1",
"Node": "foobar",
}
```
```javascript
{
"Datacenter": "dc1",
"Node": "foobar",
"CheckID": "service:redis1"
}
```
```javascript
{
"Datacenter": "dc1",
"Node": "foobar",
"ServiceID": "redis1",
}
```
The behavior of the endpoint depends on what keys are provided. The endpoint
2015-02-08 17:44:36 +00:00
requires `Node` to be provided while `Datacenter` will be defaulted
to match that of the agent. If only `Node` is provided, the node and
2015-01-18 00:28:53 +00:00
all associated services and checks are deleted. If `CheckID` is provided, only
2015-02-08 17:44:36 +00:00
that check is removed. If `ServiceID` is provided, the
2015-02-08 17:49:02 +00:00
service and its associated health check (if any) are removed.
2015-01-18 00:28:53 +00:00
2015-06-15 18:45:08 +00:00
An optional ACL token may be provided to perform the deregister action by adding
a `WriteRequest` block to the payload, like this:
```javascript
{
"WriteRequest": {
"Token": "foo"
}
}
```
2015-01-18 00:28:53 +00:00
If the API call succeeds a 200 status code is returned.
### <a name="catalog_datacenters"></a> /v1/catalog/datacenters
2016-11-25 16:00:02 +00:00
This endpoint is hit with a `GET` and is used to return all the
2015-01-18 00:28:53 +00:00
datacenters that are known by the Consul server.
2015-07-02 22:36:59 +00:00
The datacenters will be sorted in ascending order based on the
estimated median round trip time from the server to the servers
in that datacenter.
2015-01-18 00:28:53 +00:00
It returns a JSON body like this:
```javascript
["dc1", "dc2"]
```
2015-02-08 17:44:36 +00:00
This endpoint does not require a cluster leader and
will succeed even during an availability outage. Therefore, it can be
used as a simple check to see if any Consul servers are routable.
2015-01-18 00:28:53 +00:00
### <a name="catalog_nodes"></a> /v1/catalog/nodes
2016-11-25 16:00:02 +00:00
This endpoint is hit with a `GET` and returns the nodes registered
2015-02-08 17:44:36 +00:00
in a given DC. By default, the datacenter of the agent is queried;
2016-11-25 18:29:55 +00:00
however, the `dc` can be provided using the `?dc=` query parameter.
2015-01-18 00:28:53 +00:00
2016-11-25 16:00:02 +00:00
Adding the optional `?near=` parameter with a node name will sort
2015-06-30 21:25:40 +00:00
the node list in ascending order based on the estimated round trip
2016-11-25 16:00:02 +00:00
time from that node. Passing `?near=_agent` will use the agent's
2015-07-24 21:30:53 +00:00
node for the sort.
2015-06-30 21:25:40 +00:00
2017-01-11 23:44:13 +00:00
In Consul 0.7.3 and later, the optional `?node-meta=` parameter can be
provided with a desired node metadata key/value pair of the form `key:value` .
This will filter the results to nodes with that pair present.
2017-01-11 22:52:31 +00:00
2015-01-18 00:28:53 +00:00
It returns a JSON body like this:
```javascript
[
{
"Node": "baz",
2016-05-19 18:41:41 +00:00
"Address": "10.1.10.11",
2016-02-07 18:56:47 +00:00
"TaggedAddresses": {
2016-08-16 17:49:03 +00:00
"lan": "10.1.10.11",
2016-02-07 18:56:47 +00:00
"wan": "10.1.10.11"
2017-01-11 23:44:13 +00:00
},
"Meta": {
"instance_type": "t2.medium"
2016-02-07 18:56:47 +00:00
}
2015-01-18 00:28:53 +00:00
},
{
"Node": "foobar",
2016-02-07 18:56:47 +00:00
"Address": "10.1.10.12",
"TaggedAddresses": {
2016-08-16 17:49:03 +00:00
"lan": "10.1.10.11",
2016-02-07 18:56:47 +00:00
"wan": "10.1.10.12"
2017-01-11 23:44:13 +00:00
},
"Meta": {
"instance_type": "t2.large"
2016-02-07 18:56:47 +00:00
}
2015-01-18 00:28:53 +00:00
}
]
```
This endpoint supports blocking queries and all consistency modes.
### <a name="catalog_services"></a> /v1/catalog/services
2016-11-25 16:00:02 +00:00
This endpoint is hit with a `GET` and returns the services registered
2015-02-08 17:44:36 +00:00
in a given DC. By default, the datacenter of the agent is queried;
2016-11-25 18:29:55 +00:00
however, the `dc` can be provided using the `?dc=` query parameter.
2015-01-18 00:28:53 +00:00
2017-01-11 23:44:13 +00:00
In Consul 0.7.3 and later, the optional `?node-meta=` parameter can be
provided with a desired node metadata key/value pair of the form `key:value` .
This will filter the results to services with that pair present.
2017-01-11 22:52:31 +00:00
2015-01-18 00:28:53 +00:00
It returns a JSON body like this:
```javascript
{
"consul": [],
"redis": [],
"postgresql": [
2016-11-25 16:00:02 +00:00
"primary",
"secondary"
2015-01-18 00:28:53 +00:00
]
}
```
2015-02-08 17:44:36 +00:00
The keys are the service names, and the array values provide all known
tags for a given service.
2015-01-18 00:28:53 +00:00
This endpoint supports blocking queries and all consistency modes.
### <a name="catalog_service"></a> /v1/catalog/service/\<service\>
2016-11-25 16:00:02 +00:00
This endpoint is hit with a `GET` and returns the nodes providing a service
2015-02-08 17:44:36 +00:00
in a given DC. By default, the datacenter of the agent is queried;
2016-11-25 18:29:55 +00:00
however, the `dc` can be provided using the `?dc=` query parameter.
2015-01-18 00:28:53 +00:00
2015-02-08 17:44:36 +00:00
The service being queried must be provided on the path. By default
2015-01-18 00:28:53 +00:00
all nodes in that service are returned. However, the list can be filtered
2016-11-25 16:00:02 +00:00
by tag using the `?tag=` query parameter.
2015-01-18 00:28:53 +00:00
2016-11-25 16:00:02 +00:00
Adding the optional `?near=` parameter with a node name will sort
2015-06-30 21:25:40 +00:00
the node list in ascending order based on the estimated round trip
2016-11-25 16:00:02 +00:00
time from that node. Passing `?near=_agent` will use the agent's
2015-07-24 21:30:53 +00:00
node for the sort.
2015-06-30 21:25:40 +00:00
2015-01-18 00:28:53 +00:00
It returns a JSON body like this:
```javascript
[
{
2016-11-18 15:33:37 +00:00
"Address": "192.168.10.10",
"TaggedAddresses": {
"lan": "192.168.10.10",
"wan": "10.0.10.10"
},
2017-01-11 23:44:13 +00:00
"Meta": {
"instance_type": "t2.medium"
}
2016-11-18 15:33:37 +00:00
"CreateIndex": 51,
"ModifyIndex": 51,
2015-01-18 00:28:53 +00:00
"Node": "foobar",
2016-11-18 15:33:37 +00:00
"ServiceAddress": "172.17.0.3",
"ServiceEnableTagOverride": false,
"ServiceID": "32a2a47f7992:nodea:5000",
"ServiceName": "foobar",
"ServicePort": 5000,
"ServiceTags": [
"tacos"
]
2015-01-18 00:28:53 +00:00
}
]
```
This endpoint supports blocking queries and all consistency modes.
2016-11-18 15:33:37 +00:00
The returned fields are as follows:
2016-11-25 16:00:02 +00:00
- `Address` : IP address of the Consul node on which the service is registered
2016-11-18 15:33:37 +00:00
- `TaggedAddresses` : List of explicit LAN and WAN IP addresses for the agent
2017-01-11 23:44:13 +00:00
- `Meta` : Added in Consul 0.7.3, a list of user-defined metadata key/value pairs for the node
2016-11-18 15:33:37 +00:00
- `CreateIndex` : Internal index value representing when the service was created
- `ModifyIndex` : Last index that modified the service
- `Node` : Node name of the Consul node on which the service is registered
2016-11-18 15:53:59 +00:00
- `ServiceAddress` : IP address of the service host — if empty, node address should be used
2016-11-18 15:33:37 +00:00
- `ServiceEnableTagOverride` : Whether service tags can be overridden on this service
2016-11-18 15:53:59 +00:00
- `ServiceID` : A unique service instance identifier
2016-11-18 15:33:37 +00:00
- `ServiceName` : Name of the service
- `ServicePort` : Port number of the service
- `ServiceTags` : List of tags for the service
2015-01-18 00:28:53 +00:00
### <a name="catalog_node"></a> /v1/catalog/node/\<node\>
2016-11-25 16:00:02 +00:00
This endpoint is hit with a `GET` and returns the node's registered services.
2015-02-08 17:44:36 +00:00
By default, the datacenter of the agent is queried;
2016-11-25 18:29:55 +00:00
however, the `dc` can be provided using the `?dc=` query parameter.
2015-02-08 17:44:36 +00:00
The node being queried must be provided on the path.
2015-01-18 00:28:53 +00:00
It returns a JSON body like this:
```javascript
{
"Node": {
"Node": "foobar",
2016-02-07 18:56:47 +00:00
"Address": "10.1.10.12",
"TaggedAddresses": {
2016-08-16 17:49:03 +00:00
"lan": "10.1.10.12",
2016-02-07 18:56:47 +00:00
"wan": "10.1.10.12"
2017-01-11 23:44:13 +00:00
},
"Meta": {
"instance_type": "t2.medium"
2016-02-07 18:56:47 +00:00
}
2015-01-18 00:28:53 +00:00
},
"Services": {
"consul": {
"ID": "consul",
"Service": "consul",
"Tags": null,
"Port": 8300
},
"redis": {
"ID": "redis",
"Service": "redis",
"Tags": [
"v1"
],
"Port": 8000
}
}
}
```
This endpoint supports blocking queries and all consistency modes.