falcon
falcon copied to clipboard
create unix-socket example
Create a unix-socket Falcon server example
Types of Changes
- Maintenance.
Contribution
- [x] I tested my changes locally.
- [x] I agree to the Developer's Certificate of Origin 1.1.
The client is okay but would it be better to show how to use the endpoint mechanism:
require 'io/endpoint/unix_endpoint'
endpoint = Async::HTTP::Endpoint.parse("http://localhost:9292", endpoint: IO::Endpoint.unix("http.ipc"))
# => #<Async::HTTP::Endpoint http://localhost:9292/ {endpoint: #<IO::Endpoint::UNIXEndpoint path="http.ipc">}>
# Just for the sake of running this in irb:
Async{binding.irb}
server = Async::HTTP::Server.for(endpoint) do |request|
Protocol::HTTP::Response[200]
end
# => #<Async::HTTP::Server:0x000000012ba770e8
server.run
# => #<Async::Task:0x0000000000042d80 /Users/samuel/.gem/ruby/ruby-3.4.7/gems/async-2.34.0/lib/async/scheduler.rb:220:in 'IO::Event::Selector::KQueue#resume'>
client = Async::HTTP::Client.new(endpoint)
# => #<Async::HTTP::Client authority="localhost:9292">
client.get("/")
# => #<Async::HTTP::Protocol::HTTP1::Response:0x4a170 status=200>