Using with Rack
Rack provides a standard interface for interacting with web servers written in Ruby.
A Dragonfly app is a Rack app, that is to say
responds to call
in a Rack-compatible way.
Running as standalone
Running rackup
with the simple config.ru
file
will start a server.
Making a GET request to the URL
will return the content stored in the default file datastore with uid (i.e. relative path) “some/uid”, if it exists.
In reality, the app will usually need configuring. See Configuration for more details.
Here’s an example of a config.ru
file for a standalone server for resizing images from publicdomainpictures.net
When you make a GET request to the URL
you get a resized image!
Middleware
Dragonfly provides a simple middleware which mounts the Dragonfly app so that it will handle requests it knows about and pass on ones it doesn’t.
GET /media/Wsdiglk...
gets handled by Dragonfly while
GET /blah
gets passed on to SomeOtherApp
.
To mount a named (i.e. non-default) Dragonfly app
you can pass a name argument to use
to_app
Dragonfly Job objects can be converted into a Rack-compatible “app” that responds to call
Visiting this Rack app will always give a 40x30 version of the image stored with uid “some/uid”.
to_response
A standard Rack response is an array composed of
Dragonfly Job objects can be converted into one of these arrays with to_response
Sinatra
to_response
plays nicely with Sinatra for creating endpoints with nice urls
Passing in env
allows the response to take into account request headers e.g. for cached responses.
Derived from theme by orderedlist