Skip to content
 
 

Repository files navigation

ngrok-rust

Crates.io docs.rs MIT licensed Apache-2.0 licensed Continuous integration

API Docs (main)

ngrok is a simplified API-first ingress-as-a-service that adds connectivity, security, and observability to your apps.

ngrok-rust is the native Rust SDK for ngrok. It lets Rust applications listen on ngrok’s global ingress network for TCP and HTTP traffic without managing IPs, NAT, certificates, or load balancers. Connections implement tokio’s AsyncRead and AsyncWrite traits, making it easy to integrate with frameworks like axum and hyper.

For working with the ngrok API, check out the ngrok Rust API Client Library.

Installation

Add ngrok to the [dependencies] section of your Cargo.toml:

cargo add ngrok

Quickstart

Create a simple HTTP server using ngrok and axum:

use ngrok::{AgentBuilder, EndpointOptions};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
    // Build and connect an ngrok agent.
    let agent = AgentBuilder::new()
        .authtoken_from_env()
        .build()
        .await?;
    agent.connect().await?;

    // Forward traffic to a local service.
    let _forwarder = agent
        .forward(
            EndpointOptions::builder()
                .url("https://your-domain.ngrok.app")
                .build(),
            "http://localhost:3000",
        )
        .await?;

    // Wait indefinitely.
    tokio::signal::ctrl_c().await?;
    Ok(())
}

See /ngrok/tests/integration.rs for more usage examples.

Changelog

Changes to ngrok-rust are tracked under CHANGELOG.md.

Join the ngrok Community

License

This project is licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in ngrok by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

About

Embed ngrok secure ingress into your Rust apps with a single line of code.

Resources

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages