supabase / postgrest-js

Isomorphic JavaScript client for PostgREST.
https://supabase.com
MIT License
965 stars 129 forks source link

How to set RPC to send by GET with query params #438

Closed digoburigo closed 3 months ago

digoburigo commented 1 year ago

Improve documentation

Link

https://supabase.github.io/postgrest-js/v2/classes/PostgrestClient.html#rpc

How to make a RPC call with GET and query params

Describe the problem

Don't have an example or how to do it

Example: GET https://postgrest-url.domain/rpc/{function}?{param}={value}...

steve-chavez commented 1 year ago

What's the use case for doing GET with postgrest-js? Right now it only does RPC through POST.

digoburigo commented 1 year ago

My use case is a postgrest connected to a replica database for read only, so POST requests don't work. Error that occurs is referenced in this StackOverflow issue, for example

steve-chavez commented 1 year ago

@digoburigo If you mark your functions with STABLE or IMMUTABLE:

CREATE FUNCTION --.. 
$$;
LANGUAGE SQL STABLE;

Then PostgREST will run it under a READ ONLY access mode. That should avoid that error.

For more details, see https://postgrest.org/en/stable/references/transactions.html#access-mode.


That being said I think we could add a parameter to rpc for using a GET. Maybe on options ({options: { get: true} }.

digoburigo commented 1 year ago

@steve-chavez oh nice, thanks for the info. Must have looked better in postgrest docs. For the options in the postgrest-js would be nice to have. Feel free to close this issue then!

markalexander commented 9 months ago

@soedirgo thanks—do you know which release this will be in, or even just the PR/commit so I can track it through?

Edit: or maybe I misunderstood the conversation above and we didn't resolve to add the option?

Another use-case: we use RPC for dashboard widget data functions that take abstracted/common params (date range, granularity, etc.). Our CDN can cache this data nicely at the edge for GET requests, but not for POST. Most CDNs have a similar dichotomy, I believe.