Sha256: 4eaa3fe3378747817c5f96b47a5e488bd366b3773f6c9e21c561116b7131c8eb

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

#!/usr/bin/env ruby
$:<< '../lib' << 'lib'

require 'goliath'
require 'goliath/plugins/latency'

# Goliath uses multi-jon, so pick your favorite JSON serializer
# require 'json'
require 'yajl'

class Echo < Goliath::API

  # reload code on every request in dev environment
  use ::Rack::Reloader, 0 if Goliath.dev?

  use Goliath::Rack::Params             # parse & merge query and body parameters
  use Goliath::Rack::DefaultMimeType    # cleanup accepted media types
  use Goliath::Rack::Formatters::JSON   # JSON output formatter
  use Goliath::Rack::Render             # auto-negotiate response format
  use Goliath::Rack::Heartbeat          # respond to /status with 200, OK (monitoring, etc)
  use Goliath::Rack::ValidationError    # catch and render validation errors

  use Goliath::Rack::Validation::RequestMethod, %w(GET)           # allow GET requests only
  use Goliath::Rack::Validation::RequiredParam, {:key => 'echo'}  # must provide ?echo= query or body param

  plugin Goliath::Plugin::Latency       # output reactor latency every second

  def process_request
    logger.info "Processing request"

    {response: env.params['echo']}
  end

  def response(env)
    [200, {}, process_request]
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
goliath-0.9.0 examples/echo.rb