How -To: Manage Datasource on Webhooks

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:

  1. 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)

  2. You create your first endpoint naming it /mywebhook/test and set it then like that:

  3. Then, you duplicate that endpoint and name it /mywebhook/production

  4. Then, in you third party tool, on each test & production environment you register the respective webhook endpoints.

In the second case, here:

  1. Determine at the beginning of your endpoints :

    1. Check on the payload the value that determine the destination DB

    2. if the webhook addresses the production DB

      1. 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

      2. you call the endpoints recursively and return its result

    3. else

      1. 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 ๐Ÿ˜„

2
1 reply