Rust Quickstart

Getting started with the Rust Sift client library

Credentials

Before starting this section be sure to retrieve your API key and the appropriate Sift URL for your provisioned environment. Instructions on how to retrieve the API key and URL and can be found in the authentication section of the documentation.

To connect to Sift's gRPC API using Rust we will use sift_rs.

  1. Begin by creating a new Rust project using cargo new and adding the sift_rs crate.

    crate add sift_rs

    In addition to sift_rs we will use the Tokio asynchronous runtime.

    crate add tokio --features full
  2. With those dependencies installed, copy-paste the following into your main.rs:

    use sift_rs::{
        gen::sift::ping::v1::{ping_service_client::PingServiceClient, PingRequest},
        grpc::{use_sift_channel, SiftChannelConfig},
    };
    use std::{env, error::Error};
     
    #[tokio::main]
    async fn main() -> Result<(), Box<dyn Error>> {
        let uri = env::var("SIFT_URI")?;
        let apikey = env::var("SIFT_API_KEY")?;
        let grpc_channel = use_sift_channel(SiftChannelConfig { uri, apikey })?;
        let response_from_sift = PingServiceClient::new(grpc_channel)
            .ping(PingRequest {})
            .await?;
        println!("{}", response_from_sift.get_ref().response);
        Ok(())
    }
  3. Execute the program from your commandline with the SIFT_URI and SIFT_API_KEY environment variables from the authentication page:

    BASE_URI=$SIFT_GRPC_URL:$PORT_NUM SIFT_API_KEY=$API_KEY cargo run

    If everything was setup correctly you should see the following printed to your standard output:

    Hello from Sift!

On this page

No Headings