Skip to content

Create your first Stir Fry!

Tim Anema edited this page Sep 7, 2026 · 1 revision

Getting started is easy! We can have an app running in a few minutes.

  1. Create your project directory mkdir my_app && cd myapp
  2. Create a Gemfile file and add the following contents:
# frozen_string_literal: true

source "https://rubygems.org"

gem "stir_fry"
gem "puma"
  1. Run bundle install
  2. Add the following to app.rb
# frozen_string_literal: true
require "stir_fry"

class Layout < StirFry::Component
end

class Home < StirFry::Component
end

class Greet < StirFry::Component
  attr_reader :name
  def initialize(name:, **)
    super
    logger.info("Greeting #{name}")
    @name = name
  end
end

class App < StirFry::App
  get "/", Home
  get "/:name", Greet
  get "/api/:name" do |name:, response:, **|
    response.json({message: "Hello #{name}!"})
  end
end

__END__
@@Layout
<html>
  <body>
    { yield }
  </body>
</html>

@@Home
<Layout>
  <h1>Hello World</h1>
</Layout>

@@Greet
<Layout>
  <h1>Hello {name}!</h1>
</Layout>
  1. Create a file config.ru with the following contents:
require_relative "app"

run App
  1. Run bundle exec stirfry and get frying!

Clone this wiki locally