From 39d522608a94e76739df61dc200c93f1aadb4a58 Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Sat, 21 Dec 2024 11:35:51 +1300 Subject: [PATCH] Documentation for how to access handlers programatically. --- readme.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/readme.md b/readme.md index 95f071b..968cc30 100644 --- a/readme.md +++ b/readme.md @@ -24,6 +24,24 @@ $ rackup Your application should now be available locally, typically `http://localhost:9292`. +### Server Handler + +You can also use `Rackup::Handler` to start a server programmatically: + +``` ruby +require 'rackup' + +# Use the default server: +handler = Rackup::Handler.default +handler.run(app, **options) + +# Use a specific server: +handler = Rackup::Handler.get('puma') +handler.run(app, **options) +``` + +Do not require specific handlers or assume they will exist/work. Instead, use the `default` method to get the best available handler. + ## (Soft) Deprecation For a long time, `rackup` (the executable and implementation) was part of `rack`, and `webrick` was the default server, included with Ruby. It made it easy to run a Rack application without having to worry about the details of the server - great for documentation and demos.