Skip to content

Commit f544368

Browse files
committed
Updated documentation.
1 parent 0888484 commit f544368

File tree

12 files changed

+205
-59
lines changed

12 files changed

+205
-59
lines changed

context/how-it-works.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ When you run `falcon serve`, Falcon creates a {ruby Falcon::Controller::Serve} w
88

99
The workers individually load a copy of your rack application. These applications are wrapped using {ruby Falcon::Adapters::Rack} which modifies the incoming {ruby Protocol::HTTP::Request} object into an `env` object suitable for your application. It also handles converting the output of your rack application `[status, headers, body]` into an instance of {ruby Falcon::Adapters::Response} which is derived from {ruby Protocol::HTTP::Response}.
1010

11+
See the [protocol-http documentation](https://socketry.github.io/protocol-http/) for more details on how it works.
12+
1113
## Server
1214

1315
The server itself is mostly implemented by {ruby Async::HTTP::Server} which in turn depends on the `protocol-http` gems for the actual protocol implementations. Therefore, Falcon is primarily a bridge between the underlying protocol objects and the Rack interface.
16+
17+
See the [async-http documentation](https://socketry.github.io/async-http/) for more details on how it works.
18+
19+
## Protocol::Rack
20+
21+
Falcon uses the `protocol-rack` gem to provide a Rack interface for the HTTP protocol. This allows you to run any Rack-compatible application with Falcon. However, Falcon itself is not a Rack server, but rather an HTTP server that can run Rack applications.
22+
23+
See the [protocol-rack documentation](https://socketry.github.io/protocol-rack/) for more details on how it works.

context/index.yaml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,21 @@ deployment:
1414
title: Deployment
1515
order: 3
1616
description: This guide explains how to use Falcon in production environments.
17-
extended-features:
18-
title: Extended Features
19-
order: 4
20-
description: This guide explains some of the extended features and functionality
21-
of Falcon.
2217
performance-tuning:
2318
title: Performance Tuning
24-
order: 5
19+
order: 4
2520
description: This guide explains the performance characteristics of Falcon.
21+
websockets:
22+
title: WebSockets
23+
order: 5
24+
description: This guide explains how to use WebSockets with Falcon.
25+
interim-responses:
26+
title: Interim Responses
27+
order: 6
28+
description: This guide explains how to use interim responses in Falcon to send
29+
early hints to the client.
2630
how-it-works:
2731
title: How It Works
28-
order: 6
32+
order: 10
2933
description: This guide gives an overview of how Falcon handles an incoming web
3034
request.

context/interim-response.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Interim Responses
2+
3+
This guide explains how to use interim responses in Falcon to send early hints to the client.
4+
5+
## Overview
6+
7+
Interim responses allow the server to send early hints to the client before the final response is ready. This can be useful for preloading resources or providing immediate feedback. They can also be used as a response to the `expect` header, allowing the server to indicate that it is ready to process the request without waiting for the full request body.
8+
9+
Since Rack does not currently have a specificatio for interim responses, you need to access the underlying HTTP response object directly.
10+
11+
~~~ruby
12+
# config.ru
13+
14+
run do |env|
15+
if request = env["protocol.http.request"]
16+
request.send_interim_response(103, [["link", "</style.css>; rel=preload; as=style"]])
17+
end
18+
end
19+
~~~

context/interim-responses.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Interim Responses
2+
3+
This guide explains how to use interim responses in Falcon to send early hints to the client.
4+
5+
## Overview
6+
7+
Interim responses allow the server to send early hints to the client before the final response is ready. This can be useful for preloading resources or providing immediate feedback. They can also be used as a response to the `expect` header, allowing the server to indicate that it is ready to process the request without waiting for the full request body.
8+
9+
Since Rack does not currently have a specificatio for interim responses, you need to access the underlying HTTP response object directly.
10+
11+
~~~ruby
12+
# config.ru
13+
14+
run do |env|
15+
if request = env["protocol.http.request"]
16+
request.send_interim_response(103, [["link", "</style.css>; rel=preload; as=style"]])
17+
end
18+
end
19+
~~~

context/rails-integration.md

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,47 @@
22

33
This guide explains how to host Rails applications with Falcon.
44

5-
**We strongly recommend using the latest stable release of Rails with Falcon.** The integration is much smoother and you will benefit from the latest features and bug fixes. This guide is primarily intended for users of Rails 8.0 and later.
5+
**We strongly recommend using the latest stable release of Rails with Falcon.**
66

7-
## Integration with Rails
7+
We now recommend using the `Falcon::Rails` gem for Rails integration. This gem provides a simple way to configure Falcon as the web server for your Rails application, and includes many conveniences for running Rails with Falcon.
8+
9+
~~~
10+
> bundle add falcon-rails
11+
~~~
12+
13+
It also includes detailed documentation for [common tasks and configurations](https://socketry.github.io/falcon-rails/).
14+
15+
## Usage
816

917
Because Rails apps are built on top of Rack, they are compatible with Falcon.
1018

1119
1. Add `gem "falcon"` to your `Gemfile` and perhaps remove `gem "puma"` once you are satisfied with the change.
1220
2. Run `falcon serve` to start a local development server.
1321

14-
We do not recommend using Rails older than v7.1 with Falcon. If you are using an older version of Rails, you should upgrade to the latest version before using Falcon.
15-
1622
Falcon assumes HTTPS by default (so that browsers can use HTTP2). To run under HTTP in development you can bind it to an explicit scheme, host and port:
1723

1824
~~~ bash
1925
falcon serve -b http://localhost:3000
2026
~~~
2127

28+
### Self-signed Development Certificates
29+
30+
The [localhost gem](https://github.com/socketry/localhost) is used to generate self-signed certificates for local development. This allows you to run Falcon with HTTPS in development without needing to set up a real certificate authority. However, you must still install the development certificate to avoid security warnings in your browser:
31+
32+
~~~bash
33+
> bundle exec bake localhost:install
34+
~~~
35+
2236
### Production
2337

24-
The `falcon serve` command is only intended to be used for local development. Follow these steps to run a production Rails app with Falcon:
38+
The `falcon serve` command is only intended to be used for local development. We recommend you use `falcon host` for production deployments.
2539

26-
1. Create a `falcon.rb` file
40+
#### Falcon Host Configuration File
41+
42+
Create a `falcon.rb` file in the root of your Rails application. This file will be used to configure the Falcon server for production. The following example binds HTTP/1 to port 3000 as is common for Rails applications:
2743

2844
~~~ ruby
29-
#!/usr/bin/env -S falcon host
45+
#!/usr/bin/env -S falcon-host
3046
# frozen_string_literal: true
3147

3248
require "falcon/environment/rack"
@@ -51,25 +67,24 @@ service hostname do
5167
end
5268
~~~
5369

54-
2. Create a `preload.rb` file
70+
#### Preloading Rails
71+
72+
Preloading is a technique used to load your Rails application into memory before forking worker processes. This can significantly improve performance by reducing the time it takes to start each worker.
5573

5674
~~~ ruby
5775
# frozen_string_literal: true
5876

5977
require_relative "config/environment"
6078
~~~
6179

62-
3. Run the production server with `bundle exec falcon host`
63-
64-
65-
## Isolation Level
80+
#### Running the Production Server
6681

67-
Rails provides the ability to change its internal isolation level from threads (default) to fibers. When you use `falcon` with Rails, it will automatically set the isolation level to fibers.
82+
To run the production server, make sure your `falcon.rb` is executable and then run it:
6883

69-
## ActionCable
70-
71-
Falcon fully supports ActionCable with the [`Async::Cable` adapter](https://github.com/socketry/async-cable).
84+
~~~ bash
85+
> bundle exec falcon.rb
86+
~~~
7287

73-
## ActiveJob
88+
## Isolation Level
7489

75-
Falcon fully supports ActiveJob with the [`Async::Job` adapter](https://github.com/socketry/async-job-adapter-active_job).
90+
Rails provides the ability to change its internal isolation level from threads (default) to fibers. When you use `falcon` with Rails, it will automatically set the isolation level to fibers as Falcon provides the appropriate Railtie.

context/websockets.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# WebSockets
2+
3+
This guide explains how to use WebSockets with Falcon.
4+
5+
## Overview
6+
7+
Falcon supports WebSockets using the [async-websocket gem](https://github.com/socketry/async-websocket). This allows you to build real-time applications that can handle bidirectional communication between the server and clients.
8+
9+
~~~ruby
10+
# config.ru
11+
12+
require "async/websocket/adapter/rack"
13+
14+
run do |env|
15+
Async::WebSocket::Adapters::Rack.open(env, protocols: ['ws']) do |connection|
16+
# Simple echo server:
17+
while message = connection.read
18+
connection.write(message)
19+
connection.flush
20+
end
21+
end or [200, {}, ["Hello World"]]
22+
end
23+
~~~

guides/extended-features/readme.md

Lines changed: 0 additions & 13 deletions
This file was deleted.

guides/how-it-works/readme.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ When you run `falcon serve`, Falcon creates a {ruby Falcon::Controller::Serve} w
88

99
The workers individually load a copy of your rack application. These applications are wrapped using {ruby Falcon::Adapters::Rack} which modifies the incoming {ruby Protocol::HTTP::Request} object into an `env` object suitable for your application. It also handles converting the output of your rack application `[status, headers, body]` into an instance of {ruby Falcon::Adapters::Response} which is derived from {ruby Protocol::HTTP::Response}.
1010

11+
See the [protocol-http documentation](https://socketry.github.io/protocol-http/) for more details on how it works.
12+
1113
## Server
1214

1315
The server itself is mostly implemented by {ruby Async::HTTP::Server} which in turn depends on the `protocol-http` gems for the actual protocol implementations. Therefore, Falcon is primarily a bridge between the underlying protocol objects and the Rack interface.
16+
17+
See the [async-http documentation](https://socketry.github.io/async-http/) for more details on how it works.
18+
19+
## Protocol::Rack
20+
21+
Falcon uses the `protocol-rack` gem to provide a Rack interface for the HTTP protocol. This allows you to run any Rack-compatible application with Falcon. However, Falcon itself is not a Rack server, but rather an HTTP server that can run Rack applications.
22+
23+
See the [protocol-rack documentation](https://socketry.github.io/protocol-rack/) for more details on how it works.

guides/interim-responses/readme.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Interim Responses
2+
3+
This guide explains how to use interim responses in Falcon to send early hints to the client.
4+
5+
## Overview
6+
7+
Interim responses allow the server to send early hints to the client before the final response is ready. This can be useful for preloading resources or providing immediate feedback. They can also be used as a response to the `expect` header, allowing the server to indicate that it is ready to process the request without waiting for the full request body.
8+
9+
Since Rack does not currently have a specificatio for interim responses, you need to access the underlying HTTP response object directly.
10+
11+
~~~ruby
12+
# config.ru
13+
14+
run do |env|
15+
if request = env["protocol.http.request"]
16+
request.send_interim_response(103, [["link", "</style.css>; rel=preload; as=style"]])
17+
end
18+
end
19+
~~~

guides/links.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ rails-integration:
44
order: 2
55
deployment:
66
order: 3
7-
extended-features:
8-
order: 4
97
performance-tuning:
8+
order: 4
9+
websockets:
1010
order: 5
11-
how-it-works:
11+
interim-responses:
1212
order: 6
13+
how-it-works:
14+
order: 10

0 commit comments

Comments
 (0)