Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow a function with single unnamed parameter to be called with POST #1735

Closed
steve-chavez opened this issue Jan 20, 2021 · 3 comments · Fixed by #1927
Closed

Allow a function with single unnamed parameter to be called with POST #1735

steve-chavez opened this issue Jan 20, 2021 · 3 comments · Fixed by #1927
Assignees
Labels
enhancement a feature, ready for implementation

Comments

@steve-chavez
Copy link
Member

Use case

Some external services have webhooks that allow to POST json to an URL. This json doesn't come with a top level key, so our Prefer: params=single-object header is ideal here.

However, some services(like Postmark) don't allow setting HTTP headers for these webhooks. The workaround here is to use the proxy to map an URL query parameter to the header, but this is not convenient.

(Also, I can't find it right now, but there was an issue/gitter comment about an embedded device having the same limitation - crippled http client)

Proposal

Allow a function with single unnamed parameter to be called with POST, without specifying params=single-object:

create or replace function bulk_email_processing(json) returns void as $_$
-- ...
$_$ language sql;
POST /rpc/bulk_email_processing

{"any": "json"}

This wouldn't work for GET, since the parameter is unnamed it can't be specified in the URL.


Right now we don't allow calling unnamed parameters on functions, so this wouldn't cause a breaking change.

@steve-chavez steve-chavez added the idea Needs of discussion to become an enhancement, not ready for implementation label Jan 20, 2021
@steve-chavez steve-chavez changed the title RPC: allow a function with single unnamed parameter to be called with POST Allow a function with single unnamed parameter to be called with POST Jan 20, 2021
@wolfgangwalther
Copy link
Member

Sounds good. jsonb should be supported as well, I think. How about generalizing this to text and bytea, too? This would allow us to post any type of body.

@steve-chavez
Copy link
Member Author

Sounds good. jsonb should be supported as well, I think. How about generalizing this to text and bytea, too?

Yes, great idea! This would also allow us to upload raw binary(#922). I think the lack of multipart could be worked around by adding data on the headers.

@steve-chavez steve-chavez added enhancement a feature, ready for implementation and removed idea Needs of discussion to become an enhancement, not ready for implementation labels Jan 21, 2021
@jsommr
Copy link

jsommr commented Jan 23, 2021

Great use of named vs unnamed parameters!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement a feature, ready for implementation
Development

Successfully merging a pull request may close this issue.

3 participants