Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Looking for rack app structure and config.ru specs?

Tags:

ruby

rack

rackup

This will probably make me look lame but still -- I can't find any formal description for either a typical rack application structure (folders/files, like public, config.ru), or the config.ru file contents.

In the Java world there's a clear definition of a web application and the parts it comprised of (WEB-INF, META-INF web.xml).

Is there a specification of a Rack web application at all? Or is it something vague like Ruby itself.

I expected to find that info somewhere on the http://rack.rubyforge.org/ site but I couldn't. Please point me in the right direction.


Although I marked this question as answered it is worth mentioning that the question itself in not very legitimate. The app structure is driven by the actual webserver/plugin combination in use, like Apache/Passenger, and not Rack.

like image 595
Oleg Mikheev Avatar asked Nov 29 '11 14:11

Oleg Mikheev


1 Answers

A Rack web application is as simple as:

class HelloWorld
  def call(env)
    [200, {"Content-Type" => "text/plain"}, ["Hello world!"]]
  end
end

and as complex as apps built on frameworks like Rails, Sinatra, and so on, built on Rack.

Pertaining to structure, you can create yours. With Rack, you generate content the way you want it to be structured. With Rack, you are basically outputting raw HTTP content.

"Introducing Rack", "32 Rack Resources to Get You Started" and "Introduction to Rack middleware" are resources to understand Rack better.

Pertaining to structure, you have freedom in organizing files to suite the webapp. You may have other Rack applications in different files; All you need is to properly require those files.

A Rack app can be any Ruby class that responds to the :call message with env, just like the HelloWorld app above.

like image 158
Igbanam Avatar answered Oct 21 '22 15:10

Igbanam