Boom. We've told Sinatra to accept
POST requests at the
/event URL and to execute some code based on those requests.
Fire up your app by running
ruby webhook.rb. Sinatra will launch a WEBrick web server and tell you what port it's running on. By default it's
4567.
Now we need to expose this running instance to the internet.
ngrok to the rescue! Follow the installation instructions, and then launch a new instance of your terminal. Run
ngrok 4567 and look for your one-off ngrok URL. If you hit your ngrok URL in a browser, you should see the default "no route" page from Sinatra.
Now configure your
SendGrid event notification app to use your ngrok URL. Don't forget to add
/event to the URL since that's the route we defined in Sinatra.
Go ahead and hit the "Test Your Integration" button, or head over to the
Mail API reference page and hit "Try It" to send an email.
Your terminal window running ngrok should show you some HTTP requests being tunneled, and you'll see the same requests in the terminal running your Sinatra app.
You'll also have an
events.txt file in your Sinatra app directory that contains something like this: