Hi there,
Just a quick tip about how to manage your datasources when dealing with webhooks and test/production environment.
It'll mainly depend if the third party tool allow test/production environment (and differentiate webhooks accordingly), like Stripe or Api.video. Or not.
In the first case, managing datasource is pretty simple:
you create a function that'll hold all the algorithm that you have to develop. You declare 1 parameters to this function:
- payload as JSON (that you'll get through the Get All Input function)
(the headers and others are in the env variables)You create your first endpoint naming it /mywebhook/test and set it then like that:
Then, you duplicate that endpoint and name it /mywebhook/production
Then, in you third party tool, on each test & production environment you register the respective webhook endpoints.
In the second case, here:
Determine at the beginning of your endpoints :
Check on the payload the value that determine the destination DB
if the webhook addresses the production DB
you have to rebuild the API Payload (and remove /change) then information that sets the destination DB, else you will enter in an endless loop) and Headers and add to those Headers the x-data-source that will point to your production
you call the endpoints recursively and return its result
else
proceed with your algorithm into the test DB
I hope this may help some of you that are wondering how to solve such a problem.
if you have any comment or event better way to do it, plz, share ๐