Using a REST API server with ngrok

Point ngrok to a local server and add the ngrok public address as an endpoint to the @rest directive.

Before you begin

This example assumes that you have a REST API running on your localhost.

About this task

ngrok exposes the REST API to a public address, so restricting your REST API with authorization is recommended. The REST API operates on an HTTP protocol and can be proxied by ngrok as an HTTP endpoint.

Procedure

  1. Run the following command anywhere in the CLI to create an HTTP endpoint for the REST API local server:
    ngrok http 8080 // change 8080 to your port number

    The following command generates the http endpoint you will use later in the API Connect Essentials schema:

    Session Status                online                                                                                                                                                                                                                          
    Account                       Test Account                                                                                                                                                                                                        
    Version                       2.3.40                                                                                                                                                                                                                          
    Region                        United States (us)                                                                                                                                                                                                              
    Web Interface                 http://127.0.0.1:1234                                                                                                                                                                                                           
    Forwarding                    http://1234addf9e2a9d.ngrok.io -> http://localhost:8080                                                                                                                                                                           
    Forwarding                    https://1234addf9e2a9d.ngrok.io -> http://localhost:8080                                                                                                                                                                          
                                                                                                                                                                                                                                                                  
    Connections                   ttl     opn     rt1     rt5     p50     p90                                                                                                                                                                                     
                                  0       0       0.00    0.00    0.00    0.00 
    The command creates a secure public address on top of the local proxy on your machine. In the example, the newly created ngrok endpoint is:
    https://1234addf9e2a9d.ngrok.io
  2. Add the ngrok endpoint to your schema as shown in the following example:
    """
    This is a dummy schema and should be replaced by your schema.
    """
    type Sample {
      title: String!
    }
    
    
    type Query {
          restNgrok: [Sample]
            @rest(
                endpoint: "https://1234addf9e2a9d.ngrok.io"
                configuration: "sample"
            )
    }

    In the API Connect Essentials schema, the @rest endpoint enables you to access the public address that was generated.