github.com/outbrain/consul@v1.4.5/website/source/api/catalog.html.md (about) 1 --- 2 layout: api 3 page_title: Catalog - HTTP API 4 sidebar_current: api-catalog 5 description: |- 6 The /catalog endpoints register and deregister nodes, services, and checks in 7 Consul. 8 --- 9 10 # Catalog HTTP API 11 12 The `/catalog` endpoints register and deregister nodes, services, and checks in 13 Consul. The catalog should not be confused with the agent, since some of the 14 API methods look similar. 15 16 ## Register Entity 17 18 This endpoint is a low-level mechanism for registering or updating 19 entries in the catalog. It is usually preferable to instead use the 20 [agent endpoints](/api/agent.html) for registration as they are simpler and 21 perform [anti-entropy](/docs/internals/anti-entropy.html). 22 23 | Method | Path | Produces | 24 | ------ | ---------------------------- | -------------------------- | 25 | `PUT` | `/catalog/register` | `application/json` | 26 27 The table below shows this endpoint's support for 28 [blocking queries](/api/index.html#blocking-queries), 29 [consistency modes](/api/index.html#consistency-modes), 30 [agent caching](/api/index.html#agent-caching), and 31 [required ACLs](/api/index.html#acls). 32 33 | Blocking Queries | Consistency Modes | Agent Caching | ACL Required | 34 | ---------------- | ----------------- | ------------- | ------------------------- | 35 | `NO` | `none` | `none` |`node:write,service:write` | 36 37 ### Parameters 38 39 - `ID` `(string: "")` - An optional UUID to assign to the node. This must be a 36-character UUID-formatted string. 40 41 - `Node` `(string: <required>)` - Specifies the node ID to register. 42 43 - `Address` `(string: <required>)` - Specifies the address to register. 44 45 - `Datacenter` `(string: "")` - Specifies the datacenter, which defaults to the 46 agent's datacenter if not provided. 47 48 - `TaggedAddresses` `(map<string|string>: nil)` - Specifies the tagged 49 addresses. 50 51 - `NodeMeta` `(map<string|string>: nil)` - Specifies arbitrary KV metadata 52 pairs for filtering purposes. 53 54 - `Service` `(Service: nil)` - Specifies to register a service. If `ID` is not 55 provided, it will be defaulted to the value of the `Service.Service` property. 56 Only one service with a given `ID` may be present per node. The service 57 `Tags`, `Address`, `Meta`, and `Port` fields are all optional. For more 58 infomation about these fields and the implications of setting them, 59 see the [Service - Agent API](https://www.consul.io/api/agent/service.html) page 60 as registering services differs between using this or the Services Agent endpoint. 61 62 - `Check` `(Check: nil)` - Specifies to register a check. The register API 63 manipulates the health check entry in the Catalog, but it does not setup the 64 script, TTL, or HTTP check to monitor the node's health. To truly enable a new 65 health check, the check must either be provided in agent configuration or set 66 via the [agent endpoint](agent.html). 67 68 The `CheckID` can be omitted and will default to the value of `Name`. As 69 with `Service.ID`, the `CheckID` must be unique on this node. `Notes` is an 70 opaque field that is meant to hold human-readable text. If a `ServiceID` is 71 provided that matches the `ID` of a service on that node, the check is 72 treated as a service level health check, instead of a node level health 73 check. The `Status` must be one of `passing`, `warning`, or `critical`. 74 75 The `Definition` field can be provided with details for a TCP or HTTP health 76 check. For more information, see the [Health Checks](/docs/agent/checks.html) page. 77 78 Multiple checks can be provided by replacing `Check` with `Checks` and 79 sending an array of `Check` objects. 80 81 - `SkipNodeUpdate` `(bool: false)` - Specifies whether to skip updating the 82 node's information in the registration. This is useful in the case where 83 only a health check or service entry on a node needs to be updated or when 84 a register request is intended to update a service entry or health check. 85 In both use cases, node information will not be overwritten, if the node is 86 already registered. Note, if the paramater is enabled for a node that doesn't 87 exist, it will still be created. 88 89 It is important to note that `Check` does not have to be provided with `Service` 90 and vice versa. A catalog entry can have either, neither, or both. 91 92 ### Sample Payload 93 94 ```json 95 { 96 "Datacenter": "dc1", 97 "ID": "40e4a748-2192-161a-0510-9bf59fe950b5", 98 "Node": "foobar", 99 "Address": "192.168.10.10", 100 "TaggedAddresses": { 101 "lan": "192.168.10.10", 102 "wan": "10.0.10.10" 103 }, 104 "NodeMeta": { 105 "somekey": "somevalue" 106 }, 107 "Service": { 108 "ID": "redis1", 109 "Service": "redis", 110 "Tags": [ 111 "primary", 112 "v1" 113 ], 114 "Address": "127.0.0.1", 115 "Meta": { 116 "redis_version": "4.0" 117 }, 118 "Port": 8000 119 }, 120 "Check": { 121 "Node": "foobar", 122 "CheckID": "service:redis1", 123 "Name": "Redis health check", 124 "Notes": "Script based health check", 125 "Status": "passing", 126 "ServiceID": "redis1", 127 "Definition": { 128 "TCP": "localhost:8888", 129 "Interval": "5s", 130 "Timeout": "1s", 131 "DeregisterCriticalServiceAfter": "30s" 132 } 133 }, 134 "SkipNodeUpdate": false 135 } 136 ``` 137 138 ### Sample Request 139 140 ```text 141 $ curl \ 142 --request PUT \ 143 --data @payload.json \ 144 http://127.0.0.1:8500/v1/catalog/register 145 ``` 146 147 ## Deregister Entity 148 149 This endpoint is a low-level mechanism for directly removing 150 entries from the Catalog. It is usually preferable to instead use the 151 [agent endpoints](/api/agent.html) for deregistration as they are simpler and 152 perform [anti-entropy](/docs/internals/anti-entropy.html). 153 154 | Method | Path | Produces | 155 | ------ | ---------------------------- | -------------------------- | 156 | `PUT` | `/catalog/deregister` | `application/json` | 157 158 The table below shows this endpoint's support for 159 [blocking queries](/api/index.html#blocking-queries), 160 [consistency modes](/api/index.html#consistency-modes), 161 [agent caching](/api/index.html#agent-caching), and 162 [required ACLs](/api/index.html#acls). 163 164 | Blocking Queries | Consistency Modes | Agent Caching | ACL Required | 165 | ---------------- | ----------------- | ------------- | -------------------------- | 166 | `NO` | `none` | `none` | `node:write,service:write` | 167 168 ### Parameters 169 170 The behavior of the endpoint depends on what keys are provided. 171 172 - `Node` `(string: <required>)` - Specifies the ID of the node. If no other 173 values are provided, this node, all its services, and all its checks are 174 removed. 175 176 - `Datacenter` `(string: "")` - Specifies the datacenter, which defaults to the 177 agent's datacenter if not provided. 178 179 - `CheckID` `(string: "")` - Specifies the ID of the check to remove. 180 181 - `ServiceID` `(string: "")` - Specifies the ID of the service to remove. The 182 service and all associated checks will be removed. 183 184 ### Sample Payloads 185 186 ```json 187 { 188 "Datacenter": "dc1", 189 "Node": "foobar" 190 } 191 ``` 192 193 ```json 194 { 195 "Datacenter": "dc1", 196 "Node": "foobar", 197 "CheckID": "service:redis1" 198 } 199 ``` 200 201 ```json 202 { 203 "Datacenter": "dc1", 204 "Node": "foobar", 205 "ServiceID": "redis1" 206 } 207 ``` 208 209 ### Sample Request 210 211 ```text 212 $ curl \ 213 --request PUT \ 214 --data @payload.json \ 215 http://127.0.0.1:8500/v1/catalog/deregister 216 ``` 217 218 ## List Datacenters 219 220 This endpoint returns the list of all known datacenters. The datacenters will be 221 sorted in ascending order based on the estimated median round trip time from the 222 server to the servers in that datacenter. 223 224 This endpoint does not require a cluster leader and will succeed even during an 225 availability outage. Therefore, it can be used as a simple check to see if any 226 Consul servers are routable. 227 228 | Method | Path | Produces | 229 | ------ | ---------------------------- | -------------------------- | 230 | `GET` | `/catalog/datacenters` | `application/json` | 231 232 The table below shows this endpoint's support for 233 [blocking queries](/api/index.html#blocking-queries), 234 [consistency modes](/api/index.html#consistency-modes), 235 [agent caching](/api/index.html#agent-caching), and 236 [required ACLs](/api/index.html#acls). 237 238 | Blocking Queries | Consistency Modes | Agent Caching | ACL Required | 239 | ---------------- | ----------------- | ------------- | ------------ | 240 | `NO` | `none` | `none` | `none` | 241 242 ### Sample Request 243 244 ```text 245 $ curl \ 246 http://127.0.0.1:8500/v1/catalog/datacenters 247 ``` 248 249 ### Sample Response 250 251 ```json 252 ["dc1", "dc2"] 253 ``` 254 255 ## List Nodes 256 257 This endpoint and returns the nodes registered in a given datacenter. 258 259 | Method | Path | Produces | 260 | ------ | ---------------------------- | -------------------------- | 261 | `GET` | `/catalog/nodes` | `application/json` | 262 263 The table below shows this endpoint's support for 264 [blocking queries](/api/index.html#blocking-queries), 265 [consistency modes](/api/index.html#consistency-modes), 266 [agent caching](/api/index.html#agent-caching), and 267 [required ACLs](/api/index.html#acls). 268 269 | Blocking Queries | Consistency Modes | Agent Caching | ACL Required | 270 | ---------------- | ----------------- | ------------- | ------------ | 271 | `YES` | `all` | `none` | `node:read` | 272 273 ### Parameters 274 275 - `dc` `(string: "")` - Specifies the datacenter to query. This will default to 276 the datacenter of the agent being queried. This is specified as part of the 277 URL as a query parameter. 278 279 - `near` `(string: "")` - Specifies a node name to sort the node list in 280 ascending order based on the estimated round trip time from that node. Passing 281 `?near=_agent` will use the agent's node for the sort. This is specified as 282 part of the URL as a query parameter. 283 284 - `node-meta` `(string: "")` - Specifies a desired node metadata key/value pair 285 of the form `key:value`. This parameter can be specified multiple times, and 286 will filter the results to nodes with the specified key/value pairs. This is 287 specified as part of the URL as a query parameter. 288 289 ### Sample Request 290 291 ```text 292 $ curl \ 293 http://127.0.0.1:8500/v1/catalog/nodes 294 ``` 295 296 ### Sample Response 297 298 ```json 299 [ 300 { 301 "ID": "40e4a748-2192-161a-0510-9bf59fe950b5", 302 "Node": "baz", 303 "Address": "10.1.10.11", 304 "Datacenter": "dc1", 305 "TaggedAddresses": { 306 "lan": "10.1.10.11", 307 "wan": "10.1.10.11" 308 }, 309 "Meta": { 310 "instance_type": "t2.medium" 311 } 312 }, 313 { 314 "ID": "8f246b77-f3e1-ff88-5b48-8ec93abf3e05", 315 "Node": "foobar", 316 "Address": "10.1.10.12", 317 "Datacenter": "dc2", 318 "TaggedAddresses": { 319 "lan": "10.1.10.11", 320 "wan": "10.1.10.12" 321 }, 322 "Meta": { 323 "instance_type": "t2.large" 324 } 325 } 326 ] 327 ``` 328 329 ## List Services 330 331 This endpoint returns the services registered in a given datacenter. 332 333 | Method | Path | Produces | 334 | ------ | ---------------------------- | -------------------------- | 335 | `GET` | `/catalog/services` | `application/json` | 336 337 The table below shows this endpoint's support for 338 [blocking queries](/api/index.html#blocking-queries), 339 [consistency modes](/api/index.html#consistency-modes), 340 [agent caching](/api/index.html#agent-caching), and 341 [required ACLs](/api/index.html#acls). 342 343 | Blocking Queries | Consistency Modes | Agent Caching | ACL Required | 344 | ---------------- | ----------------- | ------------- | -------------- | 345 | `YES` | `all` | `none` | `service:read` | 346 347 ### Parameters 348 349 - `dc` `(string: "")` - Specifies the datacenter to query. This will default to 350 the datacenter of the agent being queried. This is specified as part of the 351 URL as a query parameter. 352 353 - `node-meta` `(string: "")` - Specifies a desired node metadata key/value pair 354 of the form `key:value`. This parameter can be specified multiple times, and 355 will filter the results to nodes with the specified key/value pairs. This is 356 specified as part of the URL as a query parameter. 357 358 ### Sample Request 359 360 ```text 361 $ curl \ 362 http://127.0.0.1:8500/v1/catalog/services 363 ``` 364 365 ### Sample Response 366 367 ```json 368 { 369 "consul": [], 370 "redis": [], 371 "postgresql": [ 372 "primary", 373 "secondary" 374 ] 375 } 376 ``` 377 378 The keys are the service names, and the array values provide all known tags for 379 a given service. 380 381 ## List Nodes for Service 382 383 This endpoint returns the nodes providing a service in a given datacenter. 384 385 | Method | Path | Produces | 386 | ------ | ---------------------------- | -------------------------- | 387 | `GET` | `/catalog/service/:service` | `application/json` | 388 389 The table below shows this endpoint's support for 390 [blocking queries](/api/index.html#blocking-queries), 391 [consistency modes](/api/index.html#consistency-modes), 392 [agent caching](/api/index.html#agent-caching), and 393 [required ACLs](/api/index.html#acls). 394 395 | Blocking Queries | Consistency Modes | Agent Caching | ACL Required | 396 | ---------------- | ----------------- | -------------------- | ------------------------ | 397 | `YES` | `all` | `background refresh` | `node:read,service:read` | 398 399 ### Parameters 400 401 - `service` `(string: <required>)` - Specifies the name of the service for which 402 to list nodes. This is specified as part of the URL. 403 404 - `dc` `(string: "")` - Specifies the datacenter to query. This will default to 405 the datacenter of the agent being queried. This is specified as part of the 406 URL as a query parameter. 407 408 - `tag` `(string: "")` - Specifies the tag to filter on. This is specified as part of 409 the URL as a query parameter. Can be used multiple times for additional filtering, 410 returning only the results that include all of the tag values provided. 411 412 - `near` `(string: "")` - Specifies a node name to sort the node list in 413 ascending order based on the estimated round trip time from that node. Passing 414 `?near=_agent` will use the agent's node for the sort. This is specified as 415 part of the URL as a query parameter. 416 417 - `node-meta` `(string: "")` - Specifies a desired node metadata key/value pair 418 of the form `key:value`. This parameter can be specified multiple times, and 419 will filter the results to nodes with the specified key/value pairs. This is 420 specified as part of the URL as a query parameter. 421 422 ### Sample Request 423 424 ```text 425 $ curl \ 426 http://127.0.0.1:8500/v1/catalog/service/my-service 427 ``` 428 429 ### Sample Response 430 431 ```json 432 [ 433 { 434 "ID": "40e4a748-2192-161a-0510-9bf59fe950b5", 435 "Node": "foobar", 436 "Address": "192.168.10.10", 437 "Datacenter": "dc1", 438 "TaggedAddresses": { 439 "lan": "192.168.10.10", 440 "wan": "10.0.10.10" 441 }, 442 "NodeMeta": { 443 "somekey": "somevalue" 444 }, 445 "CreateIndex": 51, 446 "ModifyIndex": 51, 447 "ServiceAddress": "172.17.0.3", 448 "ServiceEnableTagOverride": false, 449 "ServiceID": "32a2a47f7992:nodea:5000", 450 "ServiceName": "foobar", 451 "ServicePort": 5000, 452 "ServiceMeta": { 453 "foobar_meta_value": "baz" 454 }, 455 "ServiceTags": [ 456 "tacos" 457 ], 458 "ServiceProxyDestination": "", 459 "ServiceProxy": { 460 "DestinationServiceName": "", 461 "DestinationServiceID": "", 462 "LocalServiceAddress": "", 463 "LocalServicePort": 0, 464 "Config": null, 465 "Upstreams": null 466 }, 467 "ServiceConnect": { 468 "Native": false, 469 "Proxy": null 470 }, 471 } 472 ] 473 ``` 474 475 - `Address` is the IP address of the Consul node on which the service is 476 registered. 477 478 - `Datacenter` is the data center of the Consul node on which the service is 479 registered. 480 481 - `TaggedAddresses` is the list of explicit LAN and WAN IP addresses for the 482 agent 483 484 - `NodeMeta` is a list of user-defined metadata key/value pairs for the node 485 486 - `CreateIndex` is an internal index value representing when the service was 487 created 488 489 - `ModifyIndex` is the last index that modified the service 490 491 - `Node` is the name of the Consul node on which the service is registered 492 493 - `ServiceAddress` is the IP address of the service host — if empty, node 494 address should be used 495 496 - `ServiceEnableTagOverride` indicates whether service tags can be overridden on 497 this service 498 499 - `ServiceID` is a unique service instance identifier 500 501 - `ServiceName` is the name of the service 502 503 - `ServiceMeta` is a list of user-defined metadata key/value pairs for the service 504 505 - `ServicePort` is the port number of the service 506 507 - `ServiceTags` is a list of tags for the service 508 509 - `ServiceKind` is the kind of service, usually "". See the Agent 510 registration API for more information. 511 512 - `ServiceProxyDestination` **Deprecated** this field duplicates 513 `ServiceProxy.DestinationServiceName` for backwards compatibility. It will be 514 removed in a future major version release. 515 516 - `ServiceProxy` is the proxy config as specified in 517 [Connect Proxies](/docs/connect/proxies.html). 518 519 - `ServiceConnect` are the [Connect](/docs/connect/index.html) settings. The 520 value of this struct is equivalent to the `Connect` field for service 521 registration. 522 523 ## List Nodes for Connect-capable Service 524 525 This endpoint returns the nodes providing a 526 [Connect-capable](/docs/connect/index.html) service in a given datacenter. 527 This will include both proxies and native integrations. A service may 528 register both Connect-capable and incapable services at the same time, 529 so this endpoint may be used to filter only the Connect-capable endpoints. 530 531 | Method | Path | Produces | 532 | ------ | ---------------------------- | -------------------------- | 533 | `GET` | `/catalog/connect/:service` | `application/json` | 534 535 Parameters and response format are the same as 536 [`/catalog/service/:service`](/api/catalog.html#list-nodes-for-service). 537 538 ## List Services for Node 539 540 This endpoint returns the node's registered services. 541 542 | Method | Path | Produces | 543 | ------ | ---------------------------- | -------------------------- | 544 | `GET` | `/catalog/node/:node` | `application/json` | 545 546 The table below shows this endpoint's support for 547 [blocking queries](/api/index.html#blocking-queries), 548 [consistency modes](/api/index.html#consistency-modes), 549 [agent caching](/api/index.html#agent-caching), and 550 [required ACLs](/api/index.html#acls). 551 552 | Blocking Queries | Consistency Modes | Agent Caching | ACL Required | 553 | ---------------- | ----------------- | ------------- | ------------------------ | 554 | `YES` | `all` | `none` | `node:read,service:read` | 555 556 ### Parameters 557 558 - `node` `(string: <required>)` - Specifies the name of the node for which 559 to list services. This is specified as part of the URL. 560 561 - `dc` `(string: "")` - Specifies the datacenter to query. This will default to 562 the datacenter of the agent being queried. This is specified as part of the 563 URL as a query parameter. 564 565 ### Sample Request 566 567 ```text 568 $ curl \ 569 http://127.0.0.1:8500/v1/catalog/node/my-node 570 ``` 571 572 ### Sample Response 573 574 ```json 575 { 576 "Node": { 577 "ID": "40e4a748-2192-161a-0510-9bf59fe950b5", 578 "Node": "foobar", 579 "Address": "10.1.10.12", 580 "Datacenter": "dc1", 581 "TaggedAddresses": { 582 "lan": "10.1.10.12", 583 "wan": "10.1.10.12" 584 }, 585 "Meta": { 586 "instance_type": "t2.medium" 587 } 588 }, 589 "Services": { 590 "consul": { 591 "ID": "consul", 592 "Service": "consul", 593 "Tags": null, 594 "Meta": {}, 595 "Port": 8300 596 }, 597 "redis": { 598 "ID": "redis", 599 "Service": "redis", 600 "Tags": [ 601 "v1" 602 ], 603 "Meta": { 604 "redis_version": "4.0" 605 }, 606 "Port": 8000 607 } 608 } 609 } 610 ```