-
Notifications
You must be signed in to change notification settings - Fork 275
Mounting Endpoints
Several Shrine plugins – upload_endpoint
, presign_endpoint
,
derivation_endpoint
, and download_endpoint
– come with Rack apps, which
can be "mounted" inside your router to handle incoming requests. Since these
apps are built on top of Rack, they can be used with any Rack-based Ruby web
framework.
Shrine.upload_endpoint(:cache)
Shrine.presign_endpoint(:cache)
Shrine.download_endpoint
Shrine.derivation_endpoint
However, different web frameworks offer a different API for mounting Rack apps. This document attempts to provide a comperhensive list of how this is done in all major Ruby web frameworks.
In Rails you can use #mount
in config/routes.rb
:
# config/routes.rb
Rails.application.routes.draw do
mount Shrine.upload_endpoint(:cache) => "/upload"
end
Sinatra doesn't offer an dedicated API, but you can still do it in your
config.ru
:
# config.ru
map "/upload" do
run Shrine.upload_enpdoint(:cache)
end
run MyApp
In Hanami you can use #mount
in config/environment.rb
:
Hanami.configure do
mount Shrine.upload_endpoint(:cache), at: "/upload"
end
In Grape you can use #mount
inside your app:
class MyApp < Grape::API
mount Shrine.upload_endpoint(:cache) => "/upload"
end
In Roda you can use #run
inside a routing tree:
class MyApp < Roda
route do |r|
r.on "upload" do
r.run Shrine.upload_enpdoint(:cache)
end
end
end
In Cuba you can use #run
inside a routing tree:
class MyApp < Cuba
define do
on "upload" do
run Shrine.upload_endpoint(:cache)
end
end
end
If your web framework doesn't support mounting Rack applications, you can
always mount it in your config.ru
:
# config.ru
map "upload" do
run Shrine.upload_endpoint(:cache)
end
run MyApp