Reputation: 11187
Rails itself is based around multiple independent processes that are stateless inbetween requests. I need to add a stateful centralized service (a game automatcher) to my Rails app.
From what little I know I should make that stateful service a rack application. Is there some tutorial out there on how to make a rack application and also importantly how to communicate with it from Rails. What is the idiomatic way to deploy it with Rails and the idiomatic place to put it in my git Rails codebase?
Upvotes: 4
Views: 240
Reputation: 11187
I got my question answered in another question:
How to read POST data in rack request
require 'json'
class Greeter
def call(env)
req = Rack::Request.new(env)
if req.post?
puts req.POST()
end
[200, {"Content-Type" => "application/json"}, [{x:"Hello World!"}.to_json]]
end
end
run Greeter.new
and use JSON.parse( req.body.read )
to parse POST data.
Upvotes: 2