1
0
Fork 0
mirror of https://github.com/sinatra/sinatra synced 2023-03-27 23:18:01 -04:00

document route return values, fixes GH #23

This commit is contained in:
Konstantin Haase 2010-09-02 21:37:07 +02:00
parent 78554ffe91
commit aaeb564a43

View file

@ -119,6 +119,35 @@ You can easily define your own conditions:
"Sorry, you lost." "Sorry, you lost."
end end
=== Return values
The return value of a route block determines at least the response body passed
on to the HTTP client, or at least the next middleware in the Rack stack.
Most commonly this is a string, as in the above examples. But other values are
also accepted.
You can return any object that would either be a valid Rack response, Rack body object
or HTTP status code:
* An Array with three elements: `[status (Fixnum), headers (Hash), response body (responds to #each)]`
* An Array with two elements: `[status (Fixnum), response body (responds to #each)]`
* An object that responds to #each and passes nothing but strings to the given block
* A Fixnum representing the status code
That way we can for instance easily implement a streaming example:
class Stream
def each
100.times { |i| yield "#{i}\n" }
end
end
get '/' do
Stream.new
rescue StandardError
[500, 'sorry, error']
end
== Static Files == Static Files
Static files are served from the <tt>./public</tt> directory. You can specify Static files are served from the <tt>./public</tt> directory. You can specify