Skip to content

Instantly share code, notes, and snippets.

@iliabylich iliabylich/app.ru
Created Aug 16, 2017

Embed
What would you like to do?
opal-browser http usage
require 'opal'
require 'opal-browser'
require 'sinatra'
builder = Opal::Builder.new
code = <<-CODE
require 'opal'
require 'native'
require 'browser'
require 'browser/http'
p 'Starting HTTP request'
Browser::HTTP.post('/', key: 'value').then do |response|
p response.text
nil
end
CODE
$opal_code = builder.build_str(code, '(inline)').to_s
get '/application.js' do
content_type 'application/javascript'
$opal_code
end
get '/' do
<<-HTML
<!doctype html>
<html>
<head>
<script src="/application.js"></script>
</head>
</html>
HTML
end
post '/' do
p params
"Server: Got #{params.inspect}"
end
run Sinatra::Application
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.