Skip to content
Janko Marohnić edited this page Nov 28, 2019 · 4 revisions

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.

Rails

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

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

Hanami

In Hanami you can use #mount in config/environment.rb:

Hanami.configure do
  mount Shrine.upload_endpoint(:cache), at: "/upload"
end

Grape

In Grape you can use #mount inside your app:

class MyApp < Grape::API
  mount Shrine.upload_endpoint(:cache) => "/upload"
end

Roda

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

Cuba

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

Rack

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