When writing the code for your new webhook handler, it's useful to be able to receive real webhooks in your development environment so you can verify your code is handling them as expected.
ngrok is a free reverse proxy tool that can create a secure tunnel to your local machine so you can receive webhooks. If you have Node.js installed, run ngrok directly from the command line using the npx
command that's included with Node.js.
The command above will generate output that looks like this:
The HTTPS URL in the output (http://3e48-20-171-41-18.ngrok.io
in the example above) is a temporary URL pointing to your local machine. Copy that URL and use it as the base of your webhook URL.
Here's an example using the replicate
JavaScript client:
Your webhook handler should now receive webhooks from Replicate. Once you've deployed your app, change the value of the webhook
URL to your production webhook handler endpoint when creating predictions.
For a real-world example of webhook handling in Next.js, check out Scribble Diffusion's codebase.