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

Support JSONB to query parameter conversion for GET in http #182

Open
kolpav opened this issue Dec 18, 2024 · 1 comment
Open

Support JSONB to query parameter conversion for GET in http #182

kolpav opened this issue Dec 18, 2024 · 1 comment

Comments

@kolpav
Copy link

kolpav commented Dec 18, 2024

Unlike http_get, the http function does not automatically convert JSONB payloads into query parameters for GET requests.
Would it be a good idea to add similar behaviour to http for consistency? Or maybe make http_get also accept http headers? Thats the main reason I am using http instead of http_get. Great project btw 👍


In http_get, JSONB data is automatically URL-encoded and appended to the URI

SELECT * FROM http_get('https://api.example.com/resource', jsonb_build_object('param1', 'value1'));

With http, this has to be done manually

SELECT * FROM http((
  'GET',
  'https://api.example.com/resource?' || urlencode(jsonb_build_object('param1', 'value1')),
  ARRAY[http_header('Authorization', 'Bearer token')],
  NULL,
  NULL
)::http_request);

By reading README.md I was expecting this would work

SELECT * FROM http((
    'GET',
    'https://api.example.com/resource',
    ARRAY[http_header('Authorization', 'Bearer token')],
    'application/x-www-form-urlencoded',
    jsonb_build_object(
      'param1', 'value1'
    )
  )::http_request);
@pramsey
Copy link
Owner

pramsey commented Mar 11, 2025

The thing is, the http() function is very much designed to just take a request. The structural difference between a GET and a POST also makes things a little hard to paper over, since in one case the data payload is going into the URL, and in another case it's going into the content. Maybe a parameter on the specialized http_get for headers is better... I was also thinking that a variadic function to create the headers array might also help in that case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants