-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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 for custom output format on GET #766
Comments
@steve-chavez i think you are overcomplicating things with this approach.
|
Although not specifically about this issue, i'd like to give you an example of what this setup can give you (and i use it in one of my examples). Say i have an RPC that returns rows of a certain type.
this is just one example of the power of having a scriptable proxy in front of postgrest |
what this method might look in you case is this:
This way with a few lines of lua, it will work on all your tables/views and the clients making the request can use all the features of postgrest (filters/select ...etc) and no special code is needed in postgrest or the db for this to work |
@ruslantalpa I understand the advantages of having nginx in front of postgrest and I have too considered doing this at the proxy level as an option with a form similar to your suggestion. But I think this formatting would be better done in the db, I don't consider doing a Also I only need this for a couple of tables, I think that doing custom logic in the proxy adds more complexity than just defining a couple of views in the db. Now aside from my use case, the other reason for this proposed feature is that I saw the similarities with the binary output case, with the same code I could support both. |
@steve-chavez this is going to be a long post, i'll have a potato at the end for you :) In terms of rules for adding new features, i always think of it as a sum/relation between the following points:
If you take your suggestion and look at it from the perspective of your example/usecase, i would say it fails all three points. Comparing my proposed solution to yours for your specific usecase: The way to implement this (looking from the perspective of binary data). As promised (potatoes) -> Oo :) |
@steve-chavez have you tried requesting only that column and specifying that you want the reply in csv format? Don't you get in that case exactly the thing you want? |
@ruslantalpa If the request is made specifying csv format it also includes the name of the column as a header so it's not exactly what I want, still requires custom proxy logic to strip the first line, having said that I totally get your point in that my particular use case doesn't merit being a new feature in postgREST seeing that I'm the only user that requested this and that there's a workaround. So I'll focus instead on the binary case and see my use case only as a possible added benefit. Regarding the control of the http response, I see that the way you mentioned could add great flexibility but don't think that is necessary for the binary use case, my initial proposal could be just enough to satisfy all the requested use cases and now that I'll close this issue and continue the discussion in the binary case issues. |
@steve-chavez something along the line of what the current prefer singular discussion, i.e. say |
you would need to add a custom accept content type https://github.com/begriffs/postgrest/blob/master/src/PostgREST/ApiRequest.hs#L61 (but wait a bit before the current PRs are merged, me and @begriffs will need to touch a few core files) |
I have a table:
I need to download a file with this table rows in the following format:
Sort of a pipe separated values format with that extra pipe at the end, this is a requirement for a local goverment entity.
Currently there's no way to output that format with just postgREST I would need some custom application code, this is a problem since I also need the security and filtering that postgREST provides.
I can construct the format in a column of a custom view, it would be convenient to have a way to tell postgREST that the JSON or CSV wrapping is not required and just output that column.
Seeing the following issues #257, #506 I see there's some overlap with my use case.
My proposal is similar to this one differing in that the required parameter only be selecting a single column
select=col
when doing anAccept: application/octet-stream
if no single col is selected a406 Not Acceptable
response could be applied.The single valued rows of the response could be concatenated taking advantage of the
string_agg
pg function, that supports text and bytea.For my text case it's appropriate that postgREST concats the rows with a
'\n'
but not sure if this is good for the binary output, if that's the case then we could just concat with''
and let the client decide the delimiter; though it would be better if the users of multiple row binary output clarify this.I already have a working custom build of postgREST with this feature, I think it would be great to support this flexibility. Glad to do a PR if we reach an agreement.
The text was updated successfully, but these errors were encountered: