Crate ngrok

source ·
Expand description

The ngrok Agent SDK MIT licensed Apache-2.0 licensed Continuous integration

Website | API Docs (unstable)

ngrok is a globally distributed reverse proxy commonly used for quickly getting a public URL to a service running inside a private network, such as on your local laptop. The ngrok agent is usually deployed inside a private network and is used to communicate with the ngrok cloud service.

This is the ngrok agent in library form, suitable for integrating directly into Rust applications. This allows you to quickly build ngrok into your application with no separate process to manage.

See /ngrok/examples/ for example usage, or the tests in /ngrok/src/

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

If you’re looking for the agent wrapper, it’s over here. See for tips on migrating.


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


ngrok = "0.10"


Alternatively, with cargo-edit:

$ cargo add ngrok


Create a simple HTTP server using ngrok and axum:

use std::net::SocketAddr;

use axum::{
use ngrok::prelude::*;

async fn main() -> anyhow::Result<()> {
    // build our application with a single route
    let app = Router::new().route(
            |ConnectInfo(remote_addr): ConnectInfo<SocketAddr>| async move {
                format!("Hello, {remote_addr:?}!\r\n")

    let tun = ngrok::Session::builder()
        // Read the token from the NGROK_AUTHTOKEN environment variable
        // Connect the ngrok session
        // Start a tunnel with an HTTP edge

    println!("Tunnel started on URL: {:?}", tun.url());

    // Instead of binding a local port like so:
    // axum::Server::bind(&"".parse().unwrap())
    // Run it with an ngrok tunnel instead!



This project is licensed under either of

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.


  • Tunnel and endpoint configuration types.
  • A prelude of traits for working with ngrok types.
  • Types for working with the ngrok session.
  • Types for working with ngrok tunnels.


  • A connection from an ngrok tunnel.
  • An ngrok session.