Should I use a single cloud function, or multiple, when handling multiple webhooks from Woocommerce with Firebase Functions? (Webhooks Best Practices)

Viewed 155

I have webhooks being sent to firebase functions for when Products, Customers, Orders, and Subscriptions are created, updated, restored, and deleted on my WooCommerce site. I am using one destination URL for all of the webhooks (16 - CRUD for Orders, Products, Customers, Subscriptions) and then they are parsed and handled in Firebase functions.

Is this single destination URL a best practice, or should I be creating a new destination URL for every webhook or even every webhook category?

I could see creating a separate one for orders vs products but creating 4 separated ones for product-update, product-create, product-restore, product-delete seems like overkill.

1 Answers

You have the ability to go with creating an express app in NodeJS for example, and for your https trigger.onRequest method, pass in your express app, and let the functions handle it from there. It keeps your code cleaner, easier to maintain. For now you are using the web-hooks you mentioned, but if in the future, modifying your express app, would be easier than creating a new cloud function.

You probably have read these docs, but just in case, leaving them here.

In the end, billing would be the same, because you are charged per invocation. Using an app would be cleaner.

Related