Rack (web Server Interface)
   HOME

TheInfoList



OR:

Rack is a modular interface between
web server A web server is computer software and underlying hardware that accepts requests via HTTP (the network protocol created to distribute web content) or its secure variant HTTPS. A user agent, commonly a web browser or web crawler, initiate ...
s 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-serve ...
s developed in the
Ruby programming language Ruby is an interpreted, high-level, general-purpose programming language which supports multiple programming paradigms. It was designed with an emphasis on programming productivity and simplicity. In Ruby, everything is an object, including p ...
. 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 t ...
s (APIs) for
web framework A web framework (WF) or web application framework (WAF) is a software framework that is designed to support the development of web applications including web services, web resources, and web APIs. Web frameworks provide a standard way to build and ...
s 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 co ...
are wrapped into a single method call handling HTTP requests and responses. Rack is used by many Ruby web frameworks and
libraries A library is a collection of materials, books or media that are accessible for use and not just for display purposes. A library provides physical (hard copies) or digital access (soft copies) materials, and may be a physical location or a vir ...
, 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 web p ...
and
Sinatra Francis Albert Sinatra (; December 12, 1915 – May 14, 1998) was an American singer and actor. Nicknamed the "Chairman of the Board" and later called "Ol' Blue Eyes", Sinatra was one of the most popular entertainers of the 1940s, 1950s, and ...
. 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, a ...
. 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 Website, websites use JavaScript on the Client (computing), client side ...
(jack.js),
Clojure Clojure (, like ''closure'') is a dynamic and functional dialect of the Lisp programming language on the Java platform. Like other Lisp dialects, Clojure treats code as data and has a Lisp macro system. The current development process is comm ...
,
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 offici ...
( 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 fro ...
(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 A query string is a part of a uniform resource locator (URL) that assigns values to specified parameters. A query string commonly includes fields added to a base URL by a Web browser or other client application, for example as part of an HTML, cho ...
) *Server information like the server name and server port *The HTTP
metavariable In logic, a metavariable (also metalinguistic variable or syntactical variable) is a symbol or symbol string which belongs to a metalanguage and stands for elements of some object language. For instance, in the sentence :''Let A and B be two sente ...
s 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 co ...
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 ''Hello'' is a salutation or greeting in the English language. It is first attested in writing from 1826. Early uses ''Hello'', with that spelling, was used in publications in the U.S. as early as the 18 October 1826 edition of the ''Norwich C ...
" 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 sa ...
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 The Internet Server Application Programming Interface (ISAPI) is an N-tier API of Internet Information Services (IIS), Microsoft's collection of Windows-based web server services. The most prominent application of IIS and ISAPI is Microsoft's we ...
Internet Server Application Programming Interface (Microsoft)


References


External links

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