HOME

TheInfoList



OR:

Rack is a modular interface between web servers and
web application A web application (or web app) is application software that is accessed using a web browser. Web applications are delivered on the World Wide Web to users with an active network connection. History In earlier computing models like client-serv ...
s developed in the Ruby programming language. With Rack,
application programming interface An application programming interface (API) is a way for two or more computer programs to communicate with each other. It is a type of software interface, offering a service to other pieces of software. A document or standard that describes how ...
s (APIs) for web frameworks and
middleware Middleware is a type of computer software that provides services to software applications beyond those available from the operating system. It can be described as "software glue". Middleware makes it easier for software developers to implement ...
are wrapped into a single method call handling HTTP requests and responses. Rack is used by many Ruby web frameworks and libraries, such as
Ruby on Rails Ruby on Rails (simplified as Rails) is a server-side web application framework written in Ruby under the MIT License. Rails is a model–view–controller (MVC) framework, providing default structures for a database, a web service, and we ...
and Sinatra. It is available as a Ruby
Gem A gemstone (also called a fine gem, jewel, precious stone, or semiprecious stone) is a piece of mineral crystal which, in cut and polished form, is used to make jewelry or other adornments. However, certain rocks (such as lapis lazuli, opal, an ...
. Many Ruby applications are called "rack-compliant". Rack has inspired similar frameworks in
JavaScript JavaScript (), often abbreviated as JS, is a programming language that is one of the core technologies of the World Wide Web, alongside HTML and CSS. As of 2022, 98% of websites use JavaScript on the client side for webpage behavior, of ...
(jack.js), Clojure,
Perl Perl is a family of two high-level, general-purpose, interpreted, dynamic programming languages. "Perl" refers to Perl 5, but from 2000 to 2019 it also referred to its redesigned "sister language", Perl 6, before the latter's name was offic ...
( Plack),
Common Lisp Common Lisp (CL) is a dialect of the Lisp programming language, published in ANSI standard document ''ANSI INCITS 226-1994 (S20018)'' (formerly ''X3.226-1994 (R1999)''). The Common Lisp HyperSpec, a hyperlinked HTML version, has been derived fr ...
(Clack), and .NET ( OWIN).


Overview

The characteristics of a Rack application is that the application object responds to the call method. The call method takes in the environment object as argument and returns the Rack response object.


Environment

The environment that is taken as argument by the call method refers to an object that has:
a) Information on the HTTP Request This includes the information like: * HTTP request method *The URL information(information that would direct to the application, information that directs to the actual location in the application, Query string) *Server information like the server name and server port *The HTTP metavariables that are received from the client b) Rack specific information This includes the information like * The version of the Rack application that is running * The URL scheme that is used, that is, if the request that is received is http or https. * The raw HTTP data. * A Ruby object for reporting errors. * Information like if the application object is simultaneously invoked from another thread or process. * Information on the server expectations and capabilities (capability of the server for connection hijacking). In case the application is being used as a middleware, the environment can have objects that would provide session information, logging capabilities, information on the size of the data that can be used for read and writes etc. In addition to these, the server can store their own data in the environment.


Rack response

The rack server object returns a response which contains three parts: the status, headers and the body. *The status contains the
HTTP status codes The Hypertext Transfer Protocol (HTTP) is an application layer protocol in the Internet protocol suite model for distributed, collaborative, hypermedia information systems. HTTP is the foundation of data communication for the World Wide Web, ...
such as 200,404. *The header contains the response for each and gives the key-value pairs. The keys have to be strings. * Body contains the final data which is sent by the server to the requester. Rack::Response provides a convenient interface to create a Rack response. The class Rack::Response is defined in lib/rack/response.rb. To use the Response class, instantiate it from the middleware layer down the stack. It can be used to modify the cookies.


Middleware in racks

Rack makes it easy to add a chain of
middleware Middleware is a type of computer software that provides services to software applications beyond those available from the operating system. It can be described as "software glue". Middleware makes it easier for software developers to implement ...
components between the application and the web server. Multiple middleware components can be used in the rack which modifies the request/response before handing it over to the next component. This is called middleware stack. The Rack server adds multiple middle middleware by default for the functionalities like showing exception with all the details, validating the request and responses according to the Rack spec etc.


Example application

A Rack-compatible " Hello World" application in
Ruby A ruby is a pinkish red to blood-red colored gemstone, a variety of the mineral corundum ( aluminium oxide). Ruby is one of the most popular traditional jewelry gems and is very durable. Other varieties of gem-quality corundum are called ...
syntax: # helloWorld.ru # The application that has the call method defined. class HelloWorld # Call method that would return the HTTP status code, the content type and the content. def call (env) 00,_,_["Hello_World" __end end run_HelloWorld.new The_server_for_the_above_code_can_be_initiated_using_"rackup_helloWorld.ru"_and_can_be_accessed_at_http://localhost:9292/_The_default_port_used_by_the_Rack_application_is_9292.


_See_also

*_ 00,_,_["Hello_World" __end end run_HelloWorld.new The_server_for_the_above_code_can_be_initiated_using_"rackup_helloWorld.ru"_and_can_be_accessed_at_http://localhost:9292/_The_default_port_used_by_the_Rack_application_is_9292.


_See_also

*_Wsgi">Python_WSGI *_ 00,_,_["Hello_World" __end end run_HelloWorld.new The_server_for_the_above_code_can_be_initiated_using_"rackup_helloWorld.ru"_and_can_be_accessed_at_http://localhost:9292/_The_default_port_used_by_the_Rack_application_is_9292.


_See_also

*_Wsgi">Python_WSGI *_PSGI">Perl_PSGI *_JSGI.html" ;"title="PSGI.html" ;"title="Wsgi.html" ;"title="Hello_World".html" ;"title="00, , ["Hello World"">00, , ["Hello World" end end run HelloWorld.new The server for the above code can be initiated using "rackup helloWorld.ru" and can be accessed at http://localhost:9292/ The default port used by the Rack application is 9292.


See also

* Wsgi">Python WSGI * PSGI">Perl PSGI * JSGI">Javascript JSGI * Python Paste * Seaside (software), Smalltalk Seaside * FastCGI * Java Servlet * Server-side JavaScript * Apache JServ Protocol * Internet Communications Engine, ZeroC Ice * Etch (protocol), Cisco Etch * ISAPI Internet Server Application Programming Interface (Microsoft)


References


External links

* {{DEFAULTSORT:Rack (Web Server Interface) Free software programmed in Ruby Software using the MIT license