Feature request: Pass array/Regexp to namespace/request methods
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 10k
- Forks
- 1.2k
- Avg merge
- 14h 38m
- Merged PRs (30d)
- 92
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the namespace and get request-handling entry points in the Grape codebase, then review how route patterns and named parameters are currently processed. Done means arrays and regular expressions work with namespace and request methods, including the named-group examples in the issue, without requiring repeated blocks.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- api
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100