Give this to your AI coding agent to complete the full quickstart automatically.
If you’d prefer to skip the boilerplate setup, you can clone the complete example from the ngrok-samples collection.
In that case, you just need to reserve a domain and add your auth token as described below to get started.
What you’ll need
- An ngrok account.
- Your ngrok auth token.
- Rust installed on your machine.
You can check this by running
rustc --versionin your terminal.
Start your app or service
Start up the app or service you’d like to put online.
This is the app that your Agent Endpoint forwards online traffic to.If you don’t have an app to work with, you can set up a basic HTTP server at port Next, create a new Rust project:Replace the contents of Navigate to the root directory of the project and run the following command to start the server:
8080.First, create a directory for your Rust project and navigate into it:src/main.rs with the following code to set up a basic HTTP server:ngrok-rust-server/src/main.rs
Install the Rust SDK
Open a new terminal, then run the following commands to create a new Rust project and install the Rust SDK:Edit your
Cargo.toml file to include the necessary dependencies:ngrok-rust-demo/Cargo.toml
Create your endpoint
Create your Agent Endpoint, which forwards public traffic to your app.In the
ngrok-rust-demo directory you created in the previous step, add the following code to your src/main.rs file.This example:- Starts an Agent Endpoint that forwards from your reserved domain to your service running on port
8080. - Secures the endpoint with a Traffic Policy that requires authentication via Google OAuth.
This example uses ngrok’s default Google OAuth application.
To use your own, see the OAuth Traffic Policy Action documentation.
ngrok-rust-demo/src/main.rs
Test your endpoint
Test your endpoint by running the following terminal command, swapping in your auth token:This prints your reserved domain URL to the terminal.
When you visit the URL, ngrok prompts you to log in with Google.
After you log in, you’ll see your app or service.If you used the example app in this quickstart, you’ll see “Hello from Rust HTTP Server!” displayed in your browser.
What’s next?
In this guide, you learned how to use the Rust SDK to create an Agent Endpoint that forwards traffic to your localhost. You saw one way to implement a Traffic Policy directly in your codebase, including an action that adds authentication to your app with no configuration required. What else can you do with these features?- Dig deeper into Traffic Policies, which enable you to grant conditional access, send custom headers, rewrite URLs, and more with your endpoints.
- Learn more about the SDKs to understand how the Rust SDK works under the hood.
- Building with Axum? Serve your router through ngrok in one call using the Axum library.
- Check out the ngrok Rust SDK repo for more code examples.
- If your use case calls for a centrally managed, always-on endpoint, instead of one that’s only available when an agent is running, proceed to getting started with Cloud Endpoints.