Skip to content
Last updated

servers

Set the addresses of a gRPC API. A .proto file has no place for them: it describes services, methods, and messages, but not where the API runs.

The overview page of the API reference lists the servers in a Servers panel. The request panel of each method shows the servers in a dropdown next to the method name, as it does for OpenAPI operations. The code samples (grpcurl, Node.js, Python, and Go) connect to the picked server. The picked server stays selected across the pages of the API.

Without servers, the overview page has no Servers panel, and the code samples connect to localhost:50051 without TLS.

Usage

Add the servers list to the grpc configuration of an API:

redocly.yaml
apis:
  cafe:
    root: ./apis/cafe/cafe.proto
    grpc:
      servers:
        - url: grpcs://grpc.cafe.example.com:443
          description: Production
        - url: grpc://localhost:50051
          description: Local

Options

OptionTypeDescription
servers[Server object]List of servers for the Servers panel and the code samples. A list in an API entry replaces the list under the root grpc key.

Server object

OptionTypeDescription
urlstringREQUIRED. Host and port of the server, with an optional scheme that sets the connection type. The port is required: grpcs:// for a TLS connection, grpc:// or no scheme for a plaintext connection. For example, grpcs://grpc.example.com:443 or localhost:50051. The Servers panel and the dropdown show a URL without a scheme as grpc://host:port. Other schemes and paths are not allowed.
descriptionstringName of the server in the Servers panel and in the dropdown. Without a description, both show only the URL.

Examples

Set servers for all gRPC APIs

The following example adds a production and a sandbox server to every gRPC API in the project:

redocly.yaml
grpc:
  servers:
    - url: grpcs://grpc.example.com:443
      description: Production
    - url: grpcs://sandbox.example.com:443
      description: Sandbox

Connect without TLS

The following example sets a local server that the samples connect to without TLS. The grpcurl sample passes -plaintext, and the other samples open an insecure channel:

redocly.yaml
apis:
  cafe:
    root: ./apis/cafe/cafe.proto
    grpc:
      servers:
        - url: grpc://localhost:50051
          description: Local

Resources

  • gRPC - Official gRPC documentation
  • info - Set the title, version, and description of a gRPC API
  • Configuration options - All the other options for your project