From aaeb564a430f9560dec360d9fc8f10c53743718a Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Thu, 2 Sep 2010 21:37:07 +0200 Subject: [PATCH] document route return values, fixes GH #23 --- README.rdoc | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/README.rdoc b/README.rdoc index 4b8cb557..72f351bd 100644 --- a/README.rdoc +++ b/README.rdoc @@ -119,6 +119,35 @@ You can easily define your own conditions: "Sorry, you lost." 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 are served from the ./public directory. You can specify