github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/website/content/api-docs/services.mdx (about)

     1  ---
     2  layout: api
     3  page_title: Services - HTTP API
     4  description: >-
     5    The /service endpoints are used to query and interact with Nomad services.
     6  ---
     7  
     8  # Service HTTP API
     9  
    10  The `/service` endpoints are used to query and interact with Nomad services.
    11  
    12  ## List Services
    13  
    14  This endpoint lists all the currently available Nomad services.
    15  
    16  | Method | Path           | Produces           |
    17  | ------ | -------------- | ------------------ |
    18  | `GET`  | `/v1/services` | `application/json` |
    19  
    20  The table below shows this endpoint's support for
    21  [blocking queries](/api-docs#blocking-queries) and
    22  [required ACLs](/api-docs#acls).
    23  
    24  | Blocking Queries | ACL Required         |
    25  | ---------------- | -------------------- |
    26  | `YES`            | `namespace:read-job` |
    27  
    28  ### Sample Request
    29  
    30  ```shell-session
    31  $ curl \
    32      https://localhost:4646/v1/services
    33  ```
    34  
    35  ```shell-session
    36  $ curl \
    37      https://localhost:4646/v1/services?namespace=*
    38  ```
    39  
    40  ### Sample Response
    41  
    42  ```json
    43  [
    44    {
    45      "Namespace": "default",
    46      "Services": [
    47        {
    48          "ServiceName": "example-cache-redis",
    49          "Tags": [
    50            "cache",
    51            "db"
    52          ]
    53        }
    54      ]
    55    }
    56  ]
    57  ```
    58  
    59  ## Read Service
    60  
    61  This endpoint reads a specific service.
    62  
    63  | Method | Path                     | Produces           |
    64  | ------ | ------------------------ | ------------------ |
    65  | `GET`  | `/service/:service_name` | `application/json` |
    66  
    67  The table below shows this endpoint's support for
    68  [blocking queries](/api-docs#blocking-queries), [consistency modes](/api-docs#consistency-modes) and
    69  [required ACLs](/api-docs#acls).
    70  
    71  | Blocking Queries | Consistency Modes | ACL Required         |
    72  | ---------------- | ----------------- | -------------------- |
    73  | `YES`            | `all`             | `namespace:read-job` |
    74  
    75  ### Parameters
    76  
    77  - `:service_name` `(string: <required>)` - Specifies the service name. This is
    78    specified as part of the path.
    79  
    80  - `namespace` `(string: "default")` - Specifies the target namespace. This
    81    parameter is used before any `filter` expression is applied.
    82  
    83  - `next_token` `(string: "")` - This endpoint supports paging. The `next_token`
    84    parameter accepts a string which identifies the next expected service. This
    85    value can be obtained from the `X-Nomad-NextToken` header from the previous
    86    response.
    87  
    88  - `per_page` `(int: 0)` - Specifies a maximum number of services to return for
    89    this request. If omitted, the response is not paginated. The value of the
    90    `X-Nomad-NextToken` header of the last response can be used as the `next_token`
    91    of the next request to fetch additional pages.
    92  
    93  - `filter` `(string: "")` - Specifies the [expression](/api-docs#filtering)
    94    used to filter the results. Consider using pagination or a query parameter to
    95    reduce resource used to serve the request.
    96  
    97  - `choose` `(string: "")` - Specifies the number of services to return and a hash
    98    key. Must be in the form `<number>|<key>`. Nomad uses [rendezvous hashing][hash] to deliver
    99    consistent results for a given key, and stable results when the number of services
   100    changes.
   101  
   102  ### Sample Request
   103  
   104  ```shell-session
   105  $ curl \
   106      https://localhost:4646/v1/service/example-cache-redis
   107  ```
   108  
   109  ### Sample Response
   110  
   111  ```json
   112  [
   113    {
   114      "Address": "127.0.0.1",
   115      "AllocID": "177160af-26f6-619f-9c9f-5e46d1104395",
   116      "CreateIndex": 14,
   117      "Datacenter": "dc1",
   118      "ID": "_nomad-task-177160af-26f6-619f-9c9f-5e46d1104395-redis-example-cache-redis-db",
   119      "JobID": "example",
   120      "ModifyIndex": 24,
   121      "Namespace": "default",
   122      "NodeID": "7406e90b-de16-d118-80fe-60d0f2730cb3",
   123      "Port": 29702,
   124      "ServiceName": "example-cache-redis",
   125      "Tags": [
   126        "db",
   127        "cache"
   128      ]
   129    },
   130    {
   131      "Address": "127.0.0.1",
   132      "AllocID": "ba731da0-6df9-9858-ef23-806e9758a899",
   133      "CreateIndex": 35,
   134      "Datacenter": "dc1",
   135      "ID": "_nomad-task-ba731da0-6df9-9858-ef23-806e9758a899-redis-example-cache-redis-db",
   136      "JobID": "example",
   137      "ModifyIndex": 35,
   138      "Namespace": "default",
   139      "NodeID": "7406e90b-de16-d118-80fe-60d0f2730cb3",
   140      "Port": 27232,
   141      "ServiceName": "example-cache-redis",
   142      "Tags": [
   143        "db",
   144        "cache"
   145      ]
   146    }
   147  ]
   148  ```
   149  
   150  ## Delete Service Registration
   151  
   152  This endpoint is used to delete an individual service registration.
   153  
   154  | Method   | Path                                    | Produces           |
   155  | -------- | --------------------------------------- | ------------------ |
   156  | `DELETE` | `/v1/service/:service_name/:service_id` | `application/json` |
   157  
   158  The table below shows this endpoint's support for
   159  [blocking queries](/api-docs#blocking-queries) and
   160  [required ACLs](/api-docs#acls).
   161  
   162  | Blocking Queries | ACL Required           |
   163  | ---------------- | ---------------------- |
   164  | `NO`             | `namespace:submit-job` |
   165  
   166  ### Parameters
   167  
   168  - `:service_name` `(string: <required>)` - Specifies the service name. This is
   169    specified as part of the path.
   170  
   171  - `:service_id` `(string: <required>)` - Specifies the service ID. This is
   172    specified as part of the path.
   173  
   174  ### Sample Request
   175  
   176  ```shell-session
   177  $ curl \
   178      --request DELETE \
   179      https://localhost:4646/v1/service/example-cache-redis/_nomad-task-ba731da0-6df9-9858-ef23-806e9758a899-redis-example-cache-redis-db
   180  ```
   181  
   182  [hash]: https://en.wikipedia.org/wiki/Rendezvous_hashing