- GET
Kemal GET parameters
examples/kemal/src/get_params.cr
require "kemal" get "/" do |env| response = "" text = env.params.query["text"]? if !text.nil? response = "You typed in <b>#{text}</b>" end %{ <form method="GET" action="/"> <input name="text"> <input type="submit" value="Echo"> </form> #{response} } end Kemal.run
examples/kemal/spec/get_params_spec.cr
ENV["KEMAL_ENV"] = "test" require "spec-kemal" require "../src/get_params" describe "Web Application" do it "renders /" do get "/" response.status_code.should eq 200 response.headers["Content-Type"].should eq "text/html" response.body.should contain(%{<form method="GET" action="/">}) response.body.should_not contain(%{You typed in <b>}) end it "renders /?text=Foo Bar" do get "/?text=Foo Bar" response.status_code.should eq 200 response.headers["Content-Type"].should eq "text/html" response.body.should contain(%{<form method="GET" action="/">}) response.body.should contain(%{You typed in <b>Foo Bar</b>}) end end
crystal spec/get_params_spec.cr