Override the default endpoint

The Rust client libraries automatically configure the endpoint for each service. Some applications may need to override the default endpoint either because their network has specific requirements, or because they need to use regional versions of the service. This guide shows you how to override the default.

Prerequisites

This guide uses the Secret Manager API. To enable this API, follow the service quickstart.

For complete setup instructions for the Rust client libraries, see Getting started with Rust.

Dependencies

You must declare the dependencies in your Cargo.toml file:

cargo add google-cloud-secretmanager-v1 google-cloud-gax

The default endpoint

First, review how to use the client libraries with the default endpoint. Start by writing some use declarations to simplify the rest of the example:

  1. Write the example in a function that receives the project ID as a parameter:

    /// # Parameters
    /// - `project_id`: the id of a Google Cloud project, or its numeric ID.
    ///   For example: `my-project`.
    pub async fn sample(project_id: &str) -> anyhow::Result<()> {

  2. Add some use declarations simplify the example code:

    pub use google_cloud_gax::paginator::ItemPaginator;
    pub use google_cloud_secretmanager_v1::client::SecretManagerService;

  3. Initialize the client using the defaults:

    let client = SecretManagerService::builder().build().await