So I was speaking with the Backend Standup guys the other day (as one does) and one of them explained a problem they were having. They were attempting to do a Stripe integration but were running into problems with the webhook portion.
For those who need a reminder, a webhook is basically a callback from an online service into your application. For example, with Stripe (a payment processing service) you can set up subscriptions with your customers, where they sign up and pay you a certain amount each month. To handle this, Stripe generates an invoice automatically, and then charges them for it, again automatically. In order to give your application some visibility into this process, you can configure Stripe to hit a specified endpoint on your application with payment updates. This also applies to things like their card being declined or expired, or them canceling the subscription through Stripe directly. All very helpful things to be notified about.
Anyway, my friend was having an issue because he was running his dev server on his local machine, which doesn’t have an external hostname, and thus didn’t have a URL he could tell Stripe to hit. What to do?
If he were using RestlessIDE (the future best web-based development environment!) this would be a non-issue. Here are the steps to set it up:
1. Create your workspace with either Port 3000 or Port 3030 set to HTTP/HTTPS.
It’s probably also a good idea to use SSL. Setting this up will tell your container to open up the port for external access over HTTP, which will be needed for the webhook.
2. Set up your application to listen on the port you chose.
The details will vary a bit depending on the specifics of your programming language/environment. In NodeJS, we typically just add a PORT=3000 to our .env and the corresponding code in the application to look there. If you’re using PHP, RestlessIDE automatically configures your web server to listen on Port 3000, so you should be all set.
3. Configure the service you’re working with to hit your RestlessIDE application.
Your Workspace will be working on a particular host name, in the format:
https://<workspace>-<username>.hosts.restlesside.com
This is where you edit your code. To access your running application (once you start it, that is!) you can just go to that same URL with Port 3000 like this:
https://<workspace>-<username>.hosts.restlesside.com:3000
You’ll need to set up your application to receive the webhook, which often involves a handshake step as you’ll need to verify that incoming request is indeed coming from the service you’re expecting. You’ll need to create an endpoint for this endpoint, let’s say /webhooks/receive. Once it’s all configured you’ll need to register this webhook somewhere in service’s UI. Just enter:
https://<workspace>-<username>.hosts.restlesside.com:3000/webhooks/receive
in the appropriate spot and you should be good to go.
See, things get a lot easier if you’re coding the web from the web. If you’re not convinced, here are 10 more reasons why coding in a browser is the best.
Til next time.
(Photo by Steve Johnson on Unsplash)

Top comments (0)