1

This is an example from Goliath:

require 'goliath'

class HelloWorld < Goliath::API
  def response(env)
    [200, {}, "hello world"]
  end
end

How does defining a class and subclassing Goliath::API results in a web server being started? Shouldn't this just define a class, not actually instantiate and execute one?

sawa
  • 165,429
  • 45
  • 277
  • 381
CodingWithSpike
  • 42,906
  • 18
  • 101
  • 138

1 Answers1

2

Goliath uses at_exit, not unlike Sinatra, Minitest, etc.

See some relevant code here, which highlights the additional handling this trick sometimes requires.

TK-421
  • 10,598
  • 3
  • 38
  • 34
  • ah! that actually explains another problem I was having where I had added some code to my program that starts listening for RabbitMQ events and so I keep the application running, and suddenly my web server stopped working. This must be why! Seems like a really odd design decision. Why not just have an explicit call to `.run!` or something similar? Anyway, thanks for the info! – CodingWithSpike Oct 16 '15 at 22:41
  • The API class is designed to make things as easy as possible. You can write your own server bits and not use API to do what you want. – dj2 Oct 17 '15 at 00:05