Skip to content

Commit 6cbf133

Browse files
Updated readme.
1 parent 6bb0ac2 commit 6cbf133

File tree

2 files changed

+22
-50
lines changed

2 files changed

+22
-50
lines changed

guides/getting-started/readme.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,25 @@ end
5353
```
5454

5555
The adapter automatically detects your Rack version (v2, v3, or v3.1+) and uses the appropriate implementation, ensuring compatibility without any configuration.
56+
57+
### Server Adapter
58+
59+
Any Rack compatible server can host `Protocol::HTTP` compatible middlewares.
60+
61+
``` ruby
62+
require "protocol/http/middleware"
63+
require "protocol/rack"
64+
65+
# Your native application:
66+
middleware = Protocol::HTTP::Middleware::HelloWorld
67+
68+
run do |env|
69+
# Convert the rack request to a compatible rich request object:
70+
request = Protocol::Rack::Request[env]
71+
72+
# Call your application
73+
response = middleware.call(request)
74+
75+
Protocol::Rack::Adapter.make_response(env, response)
76+
end
77+
```

readme.md

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -17,56 +17,6 @@ Please see the [project documentation](https://socketry.github.io/protocol-rack/
1717

1818
- [Request and Response Handling](https://socketry.github.io/protocol-rack/guides/request-response/index) - This guide explains how to work with requests and responses when bridging between Rack and `Protocol::HTTP`, covering advanced use cases and edge cases.
1919

20-
### Application Adapter
21-
22-
Given a rack application, you can adapt it for use on `async-http`:
23-
24-
``` ruby
25-
require "async"
26-
require "async/http/server"
27-
require "async/http/client"
28-
require "async/http/endpoint"
29-
require "protocol/rack/adapter"
30-
31-
app = proc{|env| [200, {}, ["Hello World"]]}
32-
middleware = Protocol::Rack::Adapter.new(app)
33-
34-
Async do
35-
endpoint = Async::HTTP::Endpoint.parse("http://localhost:9292")
36-
37-
server_task = Async(transient: true) do
38-
server = Async::HTTP::Server.new(middleware, endpoint)
39-
server.run
40-
end
41-
42-
client = Async::HTTP::Client.new(endpoint)
43-
puts client.get("/").read
44-
# "Hello World"
45-
end
46-
```
47-
48-
### Server Adapter
49-
50-
While not tested, in theory any Rack compatible server can host `Protocol::HTTP` compatible middlewares.
51-
52-
``` ruby
53-
require "protocol/http/middleware"
54-
require "protocol/rack"
55-
56-
# Your native application:
57-
middleware = Protocol::HTTP::Middleware::HelloWorld
58-
59-
run do |env|
60-
# Convert the rack request to a compatible rich request object:
61-
request = Protocol::Rack::Request[env]
62-
63-
# Call your application
64-
response = middleware.call(request)
65-
66-
Protocol::Rack::Adapter.make_response(env, response)
67-
end
68-
```
69-
7020
## Releases
7121

7222
Please see the [project releases](https://socketry.github.io/protocol-rack/releases/index) for all releases.

0 commit comments

Comments
 (0)