This is a very simple example of an Apigee API proxy that handles Websocket.
Contents:
- example ws server implemented in nodejs
- example API "pass-through" proxy that proxies Websocket
This example is not an official Google product, nor is it part of an official Google product.
I've made a screencast walking through all this.
- npm 8.30 or later
- node 16 or later
- Apigee X or hybrid
-
Open a terminal window
-
cd into the directory for the server
cd server -
install the prerequisites
npm install -
start the server:
node ./server
-
Download the ngrok tool from ngrok.com. This is a local application that exposes a local system to the internet, temporarily.
-
open a separate terminal window
-
within that terminal window, run ngrok to expose port 5950
ngrok http 5950You will see an ngrok DNS name. This is the name at which you can reach your local server, over the internet. An example might be http://7959-50-35-82-179.ngrok.io Your URL will be different!
-
modify the apiproxy to specify the ngrok endpoint that your ngrok command provided.
-
Zip up the apiproxy directory, and import the proxy via the UI. OR, use your favorite command line tool to import and deploy the API proxy.
-
Direct:
Specify the connection url as the ngrok.io URL, something like wss://7959-50-35-82-179.ngrok.io Your URL will be different!
Click the connect button. Then, send messages. Switch to the terminal window to see your nodejs server. It should indicate that it has received messages and sent responses.
-
via Apigee proxy:
Disconnect in postman.
Now specify the connection url as wss://YOUR-DNS-NAME-For-APIGEE/ws-passthrough
Click the connect button. Again, send messages. Switch to the terminal window to see your nodejs server. Again you should see log messages indicating activity.
Stop the ngrok server, with ^C in the window. Do the same for the nodejs server. Undeploy the websocket proxy from your org. All done!