What you’ll need
- An ngrok account.
- A reserved domain.
Using the dashboard
- In the ngrok dashboard, select the Endpoints & Traffic Policy Tab.
- If you already have a Cloud Endpoint to use, select it and move on to the next step. Otherwise, follow these steps to create one.
- At the top-right of the page, select New Endpoint. In the modal that appears, select Cloud Endpoint.
- In the next step, select the Public binding. In the URL field add the reserved domain you created earlier.
- Select Create Endpoint, and you should be taken to that endpoint’s page.
- After selecting or creating an endpoint, you’ll be taken to the endpoint’s page, where you can add a Traffic Policy. Add the following yaml to create a basic policy, then select Save.
Example policy
- After applying the policy, visit your reserved domain. You should see the “Hello, World!” message displayed in your browser.
Using the API
To apply a Traffic Policy to a Cloud Endpoint using the ngrok API, you’ll need:- The ngrok Agent CLI installed.
- Your ngrok API key.
These instructions use the ngrok agent CLI to interact with the API. You can also use the HTTP API.
1. Add your API key to the Agent
Create an API key on your ngrok dashboard and then run the following in your terminal:2. Create your Traffic Policy file
Create a file namedpolicy.yml with the following contents:
3. Create your Cloud Endpoint via the API
Create your Cloud Endpoint via the API by running the following in your terminal (make sure to replace<your-reserve-domain> with your reserved domain):
4. Test it out
Once you have created your Cloud Endpoint you can now open the URL in your web browser. You should see the “Hello, World!” message displayed in your browser.What’s next?
To learn more about ngrok’s Traffic Policy and its capabilities, check out the following resources:- Learn how the Traffic Policy engine works under the hood.
- Check out the example gallery to see Traffic Policy in real-world scenarios.
- The list of available actions, macros and variables you can use.