• Stars
    star
    271
  • Rank 146,260 (Top 3 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created over 1 year ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

The ngrok Agent SDK

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

Website | API Docs (main)

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

ngrok-rust, our native and idiomatic crate for adding a public internet address with secure ingress traffic directly into your Rust apps 🦀. If you’ve used ngrok in the past, you can think of ngrok-rust as the ngrok agent packaged as a Rust crate.

ngrok-rust lets developers serve Rust services on the internet in a single statement without setting up low-level network primitives like IPs, NAT, certificates, load balancers, and even ports! Applications using ngrok-rust listen on ngrok’s global ingress network for TCP and HTTP traffic. ngrok-rust listeners are usable with hyper Servers, and connections implement tokio’s AsyncRead and AsyncWrite traits. This makes it easy to add ngrok-rust into any application that’s built on hyper, such as the popular axum HTTP framework.

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

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 UPGRADING.md for tips on migrating.

Installation

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

...

[dependencies]
ngrok = "0.12"

...

Alternatively, with cargo add:

$ cargo add ngrok

Quickstart

Create a simple HTTP server using ngrok and axum:

Cargo.toml:

[package]
name = "ngrok-axum-example"
version = "0.1.0"
edition = "2021"

[dependencies]
ngrok = { version="0.12", features=["axum"] }
tokio = { version = "1.26", features = ["full"] }
axum = "0.6"
anyhow = "1.0"

src/main.rs:

use std::net::SocketAddr;

use axum::{
    extract::ConnectInfo,
    routing::get,
    Router,
};
use ngrok::prelude::*;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    // build our application with a single route
    let app = Router::new().route(
        "/",
        get(
            |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
        .authtoken_from_env()
        // Connect the ngrok session
        .connect()
        .await?
        // Start a tunnel with an HTTP edge
        .http_endpoint()
        .listen()
        .await?;

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

    // Instead of binding a local port like so:
    // axum::Server::bind(&"0.0.0.0:8000".parse().unwrap())
    // Run it with an ngrok tunnel instead!
    axum::Server::builder(tun)
        .serve(app.into_make_service_with_connect_info::<SocketAddr>())
        .await
        .unwrap();

    Ok(())
}

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.

More Repositories

1

ngrok-go

Embed ngrok secure ingress into your Go apps as a net.Listener with a single line of code.
Go
597
star
2

sqlmw

Interceptors for database/sql
Go
457
star
3

kubernetes-ingress-controller

The official ngrok Ingress Controller for Kubernetes
Go
170
star
4

webhooks.fyi

webhooks.fyi site
JavaScript
142
star
5

firewall_toolkit

golang library and tools for managing nftables
Go
80
star
6

ngrok-python

Embed ngrok secure ingress into your Python apps with a single line of code.
Rust
80
star
7

ngrok-javascript

Embed ngrok secure ingress into your Node.js apps with a single line of code.
Rust
75
star
8

docker-ngrok

docker images for the ngrok agent
Nix
47
star
9

ngrok-api-go

ngrok API client library for Golang
Go
41
star
10

ngrok-docs

ngrok's official documentation
JavaScript
35
star
11

ngrok-api-java

ngrok API client library for Java
Java
21
star
12

tableroll

Go
19
star
13

ngrok-java

Embed ngrok secure ingress into your Java apps with a single line of code.
Java
17
star
14

terraform-provider-ngrok

Ngrok exposes local servers behind NATs and firewalls to the public internet over secure tunnels. This provider helps you manage those resources via Terraform.
Go
17
star
15

ngrok-webhook-nodejs-sample

Sample webhook listener using NodeJS and ExpressJS
JavaScript
16
star
16

ngrok-api-python

ngrok API client library for Python
Python
15
star
17

ngrok-api-ruby

ngrok API client library for Ruby
Ruby
13
star
18

ngrok-api-typescript

ngrok API client library for Typescript and Javascript
TypeScript
7
star
19

ngrok-api-dotnet

ngrok API client library for .NET
C#
7
star
20

ngrok-api-scala

ngrok API client library for Scala
Scala
5
star
21

ngrok-docker-extension

ngrok Docker Desktop Extension
TypeScript
5
star
22

ngrok-systemd

5
star
23

muxado-go

Stream multiplexing for Go
Go
4
star
24

ngrok-tutorial

This will help us learn ngrok
JavaScript
4
star
25

choco-ngrok

ngrok agent chocolatey package
PowerShell
3
star
26

ngrok-api-rs

ngrok API client library for Rust
Rust
3
star
27

ngrok-java-demo

Demonstrates how to use ngrok-java
Java
2
star
28

ngrok-ipaas-example

Example of a Remote API for integration with iPaaS solutions
JavaScript
1
star
29

mantle

@ngrok/mantle ui component library
TypeScript
1
star
30

ngrok-nix

Nix
1
star
31

homebrew-ngrok

ngrok agent homebrew tap
Ruby
1
star
32

ngrok-sdk-serverless-example

An example of using the ngrok-js NodeJS SDK in a serverless AWS App Runner application.
JavaScript
1
star
33

examples

Sample Project using ngrok
Go
1
star