DEV Community

Discussion on: Get list of WooCommerce products and variations

Collapse
 
theoutlander profile image
Nick Karnik

This is a general design problem.

If I were calling this from a frontend where I had an intermediate server, I would create a single endpoint on my server side which would call the other two URL's. Then, I would aggregate everything and return a response. In addition, I would make it somewhat flexible so I could pass it the type of format I want the data returned in. For instance {host}/api/products/variations?format=csv.

If this were in the backend, you can do it similarly with a function call that would make a call to the two endpoints and merge the data.

On the other hand, if I were calling WooCommerce directly from my frontend, I would create a function as mentioned earlier and fetch the data from both the endpoints and aggregate it. You can use something like Promise.all to accomplish that.