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.
Add ngrok to the [dependencies] section of your Cargo.toml:
cargo add ngrokCreate 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.
Changes to ngrok-rust are tracked under CHANGELOG.md.
- Check out our official docs
- Read about updates on our blog
- Open an issue or pull request
- Join our Slack community
- Follow us on X / Twitter (@ngrokHQ)
- Subscribe to our Youtube channel (@ngrokHQ)
This project is licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
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.