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

Feature request: Pass array/Regexp to namespace/request methods #931

Open
elado opened this issue Feb 18, 2015 · 1 comment
Open

Feature request: Pass array/Regexp to namespace/request methods #931

elado opened this issue Feb 18, 2015 · 1 comment

Comments

@elado
Copy link
Contributor

elado commented Feb 18, 2015

Currently, if I have 2 endpoints I want to merge into one, all I can do is to loop and create requests:

%w(a b c).each do |key|
  namespace key do
    get do
      "hello #{key}"
    end
  end
end

%w(e f g).each do |key|
  namespace key do
    get do
      "hello again #{key}"
    end
  end
end

In the case above, I can't use named namespace (namespace ":key") because it'll take over both request groups.

A nicer way would be to be able to send an array or regexp to namespace or get:

namespace %w(a b c) do
  get do
    "hello"
  end
end

namespace %r[^(?<key>e|f|g)$] do # regexp to support named groups
  get do
    "hello #{params[:key]}"
  end
end

get %r[^(?<key>h|i|j)$] do
  "hello #{params[:key]}"
end

Kind of aliasing same requests to a single block (also saves memory) for API changes, backward compatibility etc.

@dblock
Copy link
Member

dblock commented Feb 20, 2015

I am not opposed to namespace (and other keywords) to take arrays of things to start. I think the regex might be a stretch though.

It would probably also help if you could mount the same API under different namespaces, which is discussed in #570

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

No branches or pull requests

2 participants