Skip to content

Commit dd0fd3b

Browse files
committed
Rewrite HAL links to make them clickable.
1 parent 60f159d commit dd0fd3b

File tree

4 files changed

+13
-0
lines changed

4 files changed

+13
-0
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ gem 'rack-cors'
66
gem 'grape-swagger'
77
gem 'activemodel'
88
gem 'kaminari', require: 'kaminari/grape'
9+
gem 'rack-rewrite'
910

1011
group :development do
1112
gem 'rake'

Gemfile.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ GEM
9999
rack-cors (0.4.0)
100100
rack-mount (0.8.3)
101101
rack (>= 1.0.0)
102+
rack-rewrite (1.4.1)
102103
rack-test (0.6.3)
103104
rack (>= 1.0)
104105
rails-deprecated_sanitizer (1.0.3)
@@ -158,6 +159,7 @@ DEPENDENCIES
158159
hyperclient
159160
kaminari
160161
rack-cors
162+
rack-rewrite
161163
rack-test
162164
rake
163165
rspec

app/acme_app.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ def self.instance
1818
end
1919
end
2020

21+
# rewrite HAL links to make them clickable in a browser
22+
use Rack::Rewrite do
23+
r302 %r{^(\/api\/\w*\/)(%7B|\{)?(.*)(%7D|\})$}, '$1'
24+
end
25+
2126
run Acme::App.new
2227
end.to_app
2328
end

spec/api/root_endpoint_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,9 @@ def app
2525
expect(JSON.parse(last_response.body)).to_not eq({})
2626
end
2727
end
28+
it 'rewrites encoded HAL links to make them clickable' do
29+
get '/api/splines/%7B?cursor,size%7D'
30+
expect(last_response.status).to eq 302
31+
expect(last_response.headers['Location']).to eq '/api/splines/'
32+
end
2833
end

0 commit comments

Comments
 (0)