chriskite/jimson — Issue #5: [Feature] Support for namespace
Author: josevalim
Created: 2012-03-07 11:26:53+00:00
State: open

I would like to discuss the possibility to built in jimson some kind of namespace support as a convenience on top of JSON-RPC. This proposal could be implemented in two ways:

## Using methods

When the a request comes and the method is "foo.bar", we would invoke "foo" on the handler object that would return another object which "bar" would be called on. However, this approach could lead to security vulnerabilities (for example, given a function returns an array, one could call methods on the Array like pack/unpack that could be CPU or SPACE intensive).

## Explicit exposure

A better approach is to whitelist which methods allow nesting, this could be in the Handler API. A proposal is the `jimson_nesting` method:

extend Jimson::Handler
jimson_namespace :service1

## My case

My case is that I want to expose several services via JSON-RPC without actually having to create many ports. For example:

module Handle
extend Jimson::Handler
def service1; Service1; end
def service2; Service2; end
end

And then I would like to invoke it as: "service1.foo".

## Client

Today, the client uses method missing and this approach doesn't work with namespace. One option is to allow namespace in the client:

service1 = client.namespace(:service1)
service1.foo

This would be a very thin wrapper around the client that would basically convert the method to "service1.foo".

What do you think? In case you are interested in something like this, please let me know and I will gladly implement it. :)