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
call in a Rack-compatible way.
Running as standalone
rackup with the simple
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!
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.
gets handled by Dragonfly while
gets passed on to
To mount a named (i.e. non-default) Dragonfly app
you can pass a name argument to
Dragonfly Job objects can be converted into a Rack-compatible “app” that responds to
Visiting this Rack app will always give a 40x30 version of the image stored with uid “some/uid”.
A standard Rack response is an array composed of
Dragonfly Job objects can be converted into one of these arrays with
to_response plays nicely with Sinatra for creating endpoints with nice urls
env allows the response to take into account request headers e.g. for cached responses.