Skip to content

Instantly share code, notes, and snippets.

@luizamboni
Created October 28, 2016 17:06
Show Gist options
  • Save luizamboni/01ed19ab1b89522478f7fcab8780d56d to your computer and use it in GitHub Desktop.
Save luizamboni/01ed19ab1b89522478f7fcab8780d56d to your computer and use it in GitHub Desktop.
api from rails app
# This file is used by Rack-based servers to start the application.
class Api
def initialize app
@app = app
end
def call(env)
req = Rack::Request.new env
command = req.POST["command"]
result = eval(command)
[ 200, {"Content-Type" => "text/json"}, [result] ]
end
end
map "/test_api" do
use Api
end
require ::File.expand_path('../config/environment', __FILE__)
run Rails.application
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment