Rack - O hério oculto de aplicações web Rub.pdf
ssuserce30e6
10 views
84 slides
Sep 09, 2024
Slide 1 of 84
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
About This Presentation
Um overview da interface Rack, destacando sua importância e como ele atua discretamente, mas com grande impacto. Exploraremos conceitos-chave como modularização e adaptabilidade, demonstrando como o Rack incorpora esses princípios de forma eficaz. Exemplos práticos, estrutura básica e conceito...
Um overview da interface Rack, destacando sua importância e como ele atua discretamente, mas com grande impacto. Exploraremos conceitos-chave como modularização e adaptabilidade, demonstrando como o Rack incorpora esses princípios de forma eficaz. Exemplos práticos, estrutura básica e conceitos como Middlewares, fluxo de execução e etc.
Size: 11.68 MB
Language: en
Added: Sep 09, 2024
Slides: 84 pages
Slide Content
Rack
O Herói oculto das aplicações web em
Ruby
@aristotelesbr
RACK
•What is it for?
•Internal Operation
•Details such as: Lifecycle,
Execution
•What can be done?
•When to use?
•The impacts of decisions
•The importance of
knowledge
About me
•Software developer
•Ruby
•Photo
•Blog
•Lenna & Lolla
@aristotelesbr
RACK?
“Rack provide a minimal, modular,
and adaptable interface for
developing web applications in Ruby”
•Essential features
•Bridge to server
•Simple to understand
•Light
•Performance
“Rack provide a minimal, modular,
and adaptable interface for
developing web applications in Ruby”
proc do |_env|
▏ [
▏ ▏ 200,
▏ ▏ { 'content-type' => 'text/html' },
▏ ▏ ['Olá, mundo! Esta é uma aplicação Rack!']
▏ ]
end
proc do |_env|
▏ [
▏ ▏ 200,
▏ ▏ { 'content-type' => 'text/html' },
▏ ▏ ['Olá, mundo! Esta é uma aplicação Rack!']
▏ ]
end
proc do |_env|
▏ [
▏ ▏ 200,
▏ ▏ { 'content-type' => 'text/html' },
▏ ▏ ['Olá, mundo! Esta é uma aplicação Rack!']
▏ ]
end
proc do |_env|
▏ [
▏ ▏ 200,
▏ ▏ { 'content-type' => 'text/html' },
▏ ▏ ['Olá, mundo! Esta é uma aplicação Rack!']
▏ ]
end
“Rack provide a minimal, modular,
and adaptable interface for
developing web applications in Ruby”
“Anatomy" of a
Middleware
class GurupiMiddleware
▏ def initialize(app)
▏ ▏ @app = app
▏ end
▏ def call(env)
▏ ▏ status, headers, body = @app.call(env)
▏ ▏ headers[‘x-gurupi'] = 'GURUPI'
▏ ▏ [status, headers, body]
▏ end
end
LIFO
Last in, First Out.
class GurupiMiddleware
▏ def initialize(app)
▏ ▏ @app = app
▏ end
▏ def call(env)
▏ ▏ status, headers, body = @app.call(env)
▏ ▏ headers['x-gurupi'] = 'GURUPI'
▏ ▏ [status, headers, body]
▏ end
end
class GurupiMiddleware
▏ def initialize(app)
▏ ▏ @app = app
▏ end
▏ def call(env)
▏ ▏ status, headers, body = @app.call(env)
▏ ▏ headers['x-gurupi'] = 'GURUPI'
▏ ▏ [status, headers, body]
▏ end
end '
How to use?
use GurupiMiddleware
require 'rack'
require_relative 'gurupi_middleware '
app = proc do |env|
▏ [
▏ ▏ 200,
▏ ▏ { 'content-type' => 'text/html' },
▏ ▏ [“Hello GURUPI"]
▏ ]
end
use GurupiMiddleware
run app
!
!
!
require 'rack'
require_relative 'gurupi_middleware '
app = proc do |env|
▏ [
▏ ▏ 200,
▏ ▏ { 'content-type' => 'text/html' },
▏ ▏ [env.inspect]
▏ ]
end
use GurupiMiddleware
use MiddlewareA
use MiddlewareB
…
run app
!
(⚠)
⏱
⏱
⏱
✅
✅
✅
✅
Production
⚠
“Rack provide a minimal, modular,
and adaptable interface for
developing web applications in Ruby”
$ bundle add puma
require ‘rack’
require ‘puma’
app = proc do |_env|
▏ [
▏ ▏ 200,
▏ ▏ { 'content-type' => 'text/html' },
▏ ▏ ['Hello GURUPI']
▏ ]
end
run app
What is Rack?
•Minimal ✅
•Modular ✅
•Adaptable ✅
Let's practice?
https://github.com/aristotelesbr/rating_app
https://github.com/aristotelesbr/rating_app
Conclusion
Is it possible to use
Ruby without Rails?
Is it possible When to
use Ruby without Rails?
Rails $
"Rack" $
"There is no free lunch”
~/Projects/examples/example_app main* ❯ rails middleware
use ActionDispatch::HostAuthorization
use Rack::Sendfile
use ActionDispatch::Static
use ActionDispatch::Executor
use ActionDispatch::ServerTiming
use ActiveSupport::Cache::Strategy::LocalCache::Middleware
use Rack::Runtime
use Rack::MethodOverride
use ActionDispatch::RequestId
use ActionDispatch::RemoteIp
use Sprockets::Rails::QuietAssets
use Rails::Rack::Logger
use ActionDispatch::ShowExceptions
use WebConsole::Middleware
use ActionDispatch::DebugExceptions
use ActionDispatch::ActionableExceptions
use ActionDispatch::Reloader
use ActionDispatch::Callbacks
use ActiveRecord::Migration::CheckPending
use ActionDispatch::Cookies
use ActionDispatch::Session::CookieStore
use ActionDispatch::Flash
use ActionDispatch::ContentSecurityPolicy::Middleware
use ActionDispatch::PermissionsPolicy::Middleware
use Rack::Head
use Rack::ConditionalGet
use Rack::ETag
use Rack::TempfileReaper
run ExampleApp::Application.routes