Rom-http: Gateway and Dataset URI paths

Hi,

I am delving into rom-rb with particular interest in rom-http for interacting with a web service.

I noticed that the default behavior of the JSON request handler clobbers the path of the dataset URI with dataset.absolute_path:

def self.call(dataset)
      uri = URI(dataset.uri)
      uri.path = dataset.absolute_path
      [...]
end

The default implementation of absolute path prepends dataset.base_path with a slash. The effect of the behavior is that the path of the gateway URI is ignored.

My question is whether this behavior is intentional. Of course one can explicitly set base_path to the full path, but that seems odd. The base HTTP endpoint of a service is often not the root path of the site, so wouldn’t it make sense to configure this in the gateway and let the “base_path” of the dataset be relative to the gateway URI path?

For the moment I am overriding the request handler to behave the way I expect, but I wonder how other folks are using the library. It seems very well designed, but this one point is puzzling me.

Thanks,
David

Could you provide an example of what’s happening vs what you think should happen instead?

Sure.

The gateway URI includes a path element:

http://localhost:8983/solr/solrbee

Now, if I create a container and initialize a repository, the URI of the underlying dataset has the correct URI (appending the base_path “select” to the gateway URI path):

irb(main):002:0> documents.root.dataset.uri 
=> #<URI::HTTP http://localhost:8983/solr/solrbee/select>

But the absolute_path of the dataset just uses the base_path prepended with a slash:

irb(main):003:0> documents.root.dataset.absolute_path
=> "/select"

irb(main):004:0> documents.root.dataset.base_path
=> "select"

As a result, the request hander (at https://github.com/rom-rb/rom-http/blob/master/lib/rom/http/handlers/json.rb#L27-L29) effectively does this:

irb(main):009:0> uri = URI(documents.root.dataset.uri)
=> #<URI::HTTP http://localhost:8983/solr/solrbee/select>
irb(main):010:0> uri.path = documents.root.dataset.absolute_path
=> "/select"

And the URI for the request is now:

irb(main):011:0> puts uri
http://localhost:8983/select

What I think should happen is that the path of the dataset URI should not be “fixed” – i.e. that it’s the responsibility of the gateway to set the base URI (as it does for the value of dataset.uri).

Thanks,
David

Just to add more context, here is the request handler I am using instead of the default one from rom-http: https://github.com/dchandekstark/solrbee/blob/main/lib/rom/solr/request_handler.rb.

(This project is a WIP, but this particular piece is solid enough.)

–David

Pull request submitted for this and a couple of other minor issues: https://github.com/rom-rb/rom-http/pull/43.

1 Like