pedrozadotdev / pocketblocks

Integration between Openblocks and Pocketbase.
https://pocketblocks.pedroza.dev
GNU Affero General Public License v3.0
65 stars 5 forks source link

Querying data from the client #52

Closed ElierHG closed 1 hour ago

ElierHG commented 1 day ago

Discussed in https://github.com/pedrozadotdev/pocketblocks/discussions/51

Originally posted by **ElierHG** November 2, 2024 Hello Andres. Thank you for your help the other day with getting started with the repo. I followed the instructions you provided, and I was able to get the dev setup working. I have a question about client app, how do I perform queries? I notice the JS runtime does not have access to fetch. For example, let say I want to hit a URL when user clicks a button, what are my options? I found in the [docs](https://pocketblocks.pedroza.dev/miscellaneous/data-sources) that you decided not to include the Sources/Query library because the integration with Pocketbase was the primary goal. That means, querying data from the Pocketbase is easy and is done using **window.pb**. But, what if we create a custom Pocketbase route, is there an existing way we can hit that route if fetch is not available? Extending Pocketbase with routes will be useful in case there is a need to get data from an external source or trigger automation in n8n or cloud functions.
pedrozadotdev commented 18 hours ago

Hi Elier. fetch is not available in JS runtime for security reasons. But your reasoning is correct. You can extend PocketBase with a custom route and use the Pocketbase SDK via the window.pb.send('/custom-pocketbase-route-path', sendOptions = {}) function.

ElierHG commented 2 hours ago

Hello Andres, thank you for that information. I didn't know pb SDK had the send() method. Can we add it to the docs in this page as a reminder, in case another beginner like me comes along?