A minimal example that doesn't require additional gems looks like this.
Using a single file
Create a puma config file config.rb
with the following content:
app do |env|
body = 'Hello, World!'
[200, { 'Content-Type' => 'text/plain', 'Content-Length' => body.length.to_s }, [body]]
end
bind 'tcp://127.0.0.1:3000'
and run puma with
puma -C /path/to/config.rb
That's it.
Using a configuration and a rackup file
In the example above, the config file contains the application itself. It makes sense to move the application to a rackup file: Create a rackup file app.ru
with the following content:
class HelloWorld
def call(env)
body = 'Hello, World!'
[200, { 'Content-Type' => 'text/plain', 'Content-Length' => body.length.to_s }, [body]]
end
end
run HelloWorld.new
Then update your config.rb
, removing the app and linking the rackup file instead:
rackup '/path/to/app.ru'
bind 'tcp://127.0.0.1:3000'
and run puma as before with
puma -C /path/to/config.rb
The example configuration file for puma is helpful. (Update: This example configuration file is no longer maintained. The authors refer to dsl.rb instead.)