Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Rack (web server interface)

From Wikipedia, the free encyclopedia
API specification for web applications in programming language Ruby
Rack, a Ruby Webserver Interface
Original authorLeah Neukirchen
DevelopersJames Tucker, Josh Peek, José Valim, Michael Fellinger, Aaron Patterson, Santiago Pastorino, Konstantin Haase
Stable release
3.0.2 / December 5, 2022; 3 years ago (2022-12-05)[1]
Operating systemCross-platform
TypeMiddleware
LicenseMIT License
Websiterack.github.io Edit this on Wikidata
Repository

Rack is a modular interface betweenweb servers andweb applications developed in theRuby programming language. With Rack,application programming interfaces (APIs) forweb frameworks andmiddleware arewrapped into a singlemethod call handlingHTTP requests andresponses.

Rack is used by many Ruby web frameworks andlibraries, such asRuby on Rails andSinatra. It is available as a RubyGem. Many Ruby applications are called "rack-compliant".[2]

Rack has inspired similar frameworks inJavaScript[3] (jack.js),Clojure,[4]Perl (Plack),Common Lisp (Clack),[5] and.NET (OWIN).[6]

Overview

[edit]

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

[edit]

Source:[7]

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
  • TheURL 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 HTTPmetavariables 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

[edit]

Source:[7]

The rack server object returns a response which contains three parts: the status, headers and the body.

  • The status contains theHTTP status codes 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 classRack::Response is defined in lib/rack/response.rb. To use theResponse class, instantiate it from the middleware layer down the stack. It can be used to modify the cookies.

Middleware in racks

[edit]

Source:[7]

Rack makes it easy to add a chain ofmiddleware 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,[8] validating the request and responses according to the Rack spec[9] etc.

Example application

[edit]

A Rack-compatible "Hello World" application inRuby syntax:

# helloWorld.ru# The application that has the call method defined.classHelloWorld# Call method that would return the HTTP status code, the content type and the content.defcall(env)[200,{"content-type"=>"text/html; charset=utf-8"},["Hello World"]]endendrunHelloWorld.new

The server for the above code can be initiated using "rackup helloWorld.ru" and can be accessed athttp://localhost:9292/ The default port used by the Rack application is 9292.

See also

[edit]

References

[edit]
  1. ^"Releases - rack/rack". Retrieved5 December 2022 – viaGitHub.
  2. ^Pancake: How To Stack and Loosely Couple Rack-Based Webapps Together. Rubyinside.com (2009-12-04). Retrieved on 2013-09-20.
  3. ^jack - introductionArchived 2014-12-17 at theWayback Machine. Jackjs.org. Retrieved on 2013-09-20.
  4. ^ring - introduction. GitHub.com. Retrieved on 2020-04-20.
  5. ^clacklisp.org. Retrieved on 2014-10-17.
  6. ^https://www.asp.net/aspnet/overview/owin-and-katana/an-overview-of-project-katana. Asp.net. Retrieved on 2014-10-01.
  7. ^abc"Documentation for rack".www.rubydoc.info. Retrieved2016-09-14.
  8. ^"Rack::ShowExceptions".www.rubydoc.info. Retrieved2016-09-14.
  9. ^"Rack::Lint".www.rubydoc.info. Retrieved2016-09-14.

External links

[edit]
Implementations
Active
Discontinued
IDE
Applications
Libraries,
frameworks
Server software
People
Other
Protocols
Server APIs
Apache modules
Topics
Browser APIs
Web APIs
WHATWG
W3C
Khronos
Others
Topics
Related topics
Retrieved from "https://en.wikipedia.org/w/index.php?title=Rack_(web_server_interface)&oldid=1305322696"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2026 Movatter.jp