Redirect internally within Goliath endpoints

298 Views Asked by At
require 'goliath'
require 'em-synchrony'
require 'em-synchrony/em-http'

class UsersSendEmail < Goliath::API
  use Goliath::Rack::Params

  def response(env)
    [200, {}, {response: 'email sent'}]
  end
end

class UsersCreate < Goliath::API
  use Goliath::Rack::Params

  def response(env)

    #this doesn't work
    http = EM::HttpRequest.new('http://localhost', :path => 'send_email').get

    [200, {}, {response: 'create'}]
  end
end

One of my Goliath endpoints is getting very complex, so I decided to cut it up and use http to communicate between them (above is a simple example of the idea). However I'm having trouble communicating between them. Not sure if this is the best idea, so open to suggestions. Thanks!

1

There are 1 best solutions below

0
On BEST ANSWER

Forgot to add in the port number. EM::HttpRequest.new('http://localhost:9000', :path => 'send_email').get

In hindsight I feel silly for asking this.