Use cases
There are many use cases where you might want to create a Postgres function in Supabase and call it in WeWeb.
Common use cases include but are not limited to:
- sending an email,
- formatting data in the backend before sending it back to WeWeb,
- doing resource-intensive calculations a browser can't handle efficiently,
- making an API call through your backend.
TIP
API calls that use a secret key should always be made through your backend.
Learn more about the difference between public and private API keys.
Postgres function example
Create a function in Supabase
In the example below, we followed Supabase's instructions to create a function that:
- accepts a
name
input, - gets a Kanye West quote from an API, and
- returns a text that says: "Hey {name}, {kanye_quote}".
Call a Supabase function in WeWeb
In WeWeb, all we have to do is:
- call the Supabase function, in our case
talk_to_kanye
- add my
name
input and bind it to the current user's nickname - test my workflow to check that the return value matches what I expected
And that's it!
That's how you can call a Supabase Postgres function via your WeWeb app.