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

Patches Dataset and JSON handler: #43

Closed
wants to merge 1 commit into from

Conversation

dchandekstark
Copy link

@dchandekstark dchandekstark commented Jan 6, 2021

- Dataset#uri incorrectly omits params from non-GET requests.
- JSONRequest clobbers URI path (see
https://discourse.rom-rb.org/t/rom-http-gateway-and-dataset-uri-paths/407)
- JSONRequest redundantly sets URI query
@dchandekstark
Copy link
Author

IMO Dataset#absolute_path should either be removed or changed to return uri.path, but I left it untouched here since that discussion is not resolved.

uri.query = param_encoder.call(params)
URI(join_path(super, path)).tap do |uri|
if params.any?
uri.query = param_encoder.call(params)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm not mistaken, this will add all params as query params, even in a POST request, which could be bad if posting a blob of text for example, and is probably not desired in most scenarios. Perhaps it would be better to add a query_params option to Dataset?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AMHOL Oh, right. :) It so happens that the app I am cutting my rom-rb teeth on uses the request body to POST JSON data. I can amend this as you suggest.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AMHOL On further thought (what a day!) the use of both query_params and params seems ... confusing. I wonder if it would be too complicated to just POST params in the body if there is no other request data? E.g., in my app I have a request_data string var https://github.com/dchandekstark/solrbee/blob/main/lib/rom/solr/dataset.rb#L12 which gets dumped into the request body. I could see dumping the params into the body if request_data is nil or empty.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it could be confusing, I'm not sure of a better way to go about it myself, I like the idea of just having params sent as the request body though and having a separate query_params option does solve that, perhaps we could have a query_params option as well as a body_params option, probably best to wait for @solnic to weigh in on this though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea of query_params and body_params, it would make things much more obvious.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AMHOL
Copy link
Member

AMHOL commented Jan 7, 2021

@dchandekstark the idea with an override-able base path is to allow for querying from a relation when that resource is nested under another resource, i.e. being able to query blog_posts by authors at /authors/:id/blog_posts, see https://github.com/PetRescue/pr-pin/blob/master/lib/pr/pin/relations/charges.rb#L29-L31 for an example of this, having said that, the default request handler doesn't handle many cases well, it doesn't add request params for non-get requests, and doesn't preserve the gateway path, as you mentioned. It may be best to update it to something similar to https://github.com/PetRescue/pr-pin/blob/master/lib/pr/pin/adapter/handlers/json_request.rb, but even then it will probably require customisation in most cases.

@dchandekstark
Copy link
Author

@AMHOL I get overriding base_path, but what Dataset#absolute_path does is nuke the base path below base_path.

@AMHOL
Copy link
Member

AMHOL commented Jan 7, 2021

@dchandekstark it doesn't in https://github.com/PetRescue/pr-pin/blob/master/lib/pr/pin/adapter/handlers/json_request.rb as that's just using the Dataset#uri method to resolve the URL, I think the use of #absolute_path in the default request handler is just an implementation error carried over from the early documentation of a request handler, we should probably update the default request handler to use Dataset#uri too, and handle non-get requests

@dchandekstark
Copy link
Author

OK, thanks @AMHOL.

@dchandekstark
Copy link
Author

I think this PR is now superseded by #44.

@dchandekstark
Copy link
Author

Closing in deference to #44.

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

Successfully merging this pull request may close these issues.

3 participants