Skip to content

Instantly share code, notes, and snippets.

@SqREL
Created March 16, 2017 10:52
Show Gist options
  • Save SqREL/64eda7e30ad0a2309bc97d3e0b551d74 to your computer and use it in GitHub Desktop.
Save SqREL/64eda7e30ad0a2309bc97d3e0b551d74 to your computer and use it in GitHub Desktop.
flashapi
require_relative
'../flashapi/lib/flashapi'
require 'eventmachine'
## APPLICATION
module Application
module Routes
extend self
def paths
{
'/' => { method: :get, responder: 'GetIndex' }
}
end
end
module GetIndex
extend FlashAPI::Responder
extend self
def render
{
status_code: 200,
body: {}
}
end
end
end
## SERVER
module FlashAPIEventMachineServer
class Handler < EventMachine::Connection
include EventMachine::HttpServer
def process_http_request
resp = EventMachine::DelegatedHttpResponse.new( self )
request = FlashAPI::Adapters::EventMachine::Request.new(
protocol: @http_protocol,
request_method: @http_request_method,
cookie: @http_cookie,
content_type: @http_content_type,
path_info: @http_path_info,
uri: @http_request_uri,
query_string: @http_query_string,
post_content: @http_post_content,
headers: @http_headers
)
application = FlashAPI::Application.run request, ::Application
resp.headers = application.headers
resp.status = application.status_code
resp.content = application.body
resp.send_response
end
end
end
EventMachine::run {
EventMachine::start_server("0.0.0.0", 8081, FlashAPIEventMachineServer::Handler)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment