Skip to main content

What youโ€™ll need

1. Add your API key to the Agent

Create an API key on your ngrok dashboard and then run the following in your terminal:
ngrok config add-api-key <your-api-key>

2. Create your Traffic Policy file

Create a file named policy.yml with the following contents:
on_http_request:
  - actions:
      - type: custom-response
        config:
          status_code: 200
          body: "Hello, World!"
This will be the Traffic Policy used on your Cloud Endpoint to respond to each HTTP request with a simple โ€œHello, World!โ€ message.

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):
ngrok api endpoints create \
  --url https://<your-reserve-domain> \
  --traffic-policy "$(<policy.yml)"

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?

Youโ€™ve now successfully set up your first Cloud Endpoint with a custom Traffic Policy via the API. To learn more about ngrokโ€™s Traffic Policy and its capabilities, check out the following resources:
โŒ˜I