-
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
217 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require "http" | ||
|
||
req = HTTP::Request.new("GET", "https://code-maven.com/page?name=Foo&[email protected]") | ||
p! req | ||
p req.resource | ||
p req.query_params | ||
p req.body |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require "http" | ||
|
||
req = HTTP::Request.new("POST", | ||
"https://code-maven.com/page", | ||
body: "name=Foo&[email protected]", | ||
headers: HTTP::Headers{"Content-Type" => "application/x-www-form-urlencoded"}) | ||
p! req | ||
p req.body # IO::Memory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
ENV["KEMAL_ENV"] = "test" | ||
require "spec-kemal" | ||
require "../src/post_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="POST" action="/">}) | ||
response.body.should_not contain(%{You typed in <b>}) | ||
end | ||
|
||
it "renders / POST text=Foo Bar" do | ||
post "/", body: "text=Foo Bar", headers: HTTP::Headers{"Content-Type" => "application/x-www-form-urlencoded"} | ||
response.status_code.should eq 200 | ||
response.headers["Content-Type"].should eq "text/html" | ||
response.body.should contain(%{<form method="POST" action="/">}) | ||
response.body.should contain(%{You typed in <b>Foo Bar</b>}) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
ENV["KEMAL_ENV"] = "test" | ||
require "spec-kemal" | ||
require "../src/route_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(%{<a href="/user/foo">/user/foo</a><br>}) | ||
response.body.should_not contain(%{received}) | ||
end | ||
|
||
it "renders /user/one" do | ||
get "/user/one" | ||
response.status_code.should eq 200 | ||
response.headers["Content-Type"].should eq "text/html" | ||
response.body.should_not contain(%{<a}) | ||
response.body.should contain(%{received fname: one}) | ||
end | ||
|
||
it "renders /user/one/two" do | ||
get "/user/one/two" | ||
response.status_code.should eq 200 | ||
response.headers["Content-Type"].should eq "text/html" | ||
response.body.should_not contain(%{<a}) | ||
response.body.should contain(%{received fname: one and lname: two}) | ||
end | ||
|
||
it "renders /user/one/two/three" do | ||
get "/user/one/two/three" | ||
response.status_code.should eq 200 # TODO should be 404 | ||
response.headers["Content-Type"].should eq "text/html" | ||
response.body.should eq "" # TODO: where is the page? | ||
end | ||
|
||
it "renders /path/1/2/3/4/5" do | ||
get "/path/1/2/3/4/5" | ||
response.status_code.should eq 200 | ||
response.headers["Content-Type"].should eq "text/html" | ||
response.body.should eq "received 1/2/3/4/5" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
require "kemal" | ||
|
||
get "/" do |env| | ||
response = "" | ||
text = env.params.query["text"]? | ||
if !text.nil? | ||
response = text | ||
end | ||
render "src/views/page.ecr", "src/views/layouts/layout.ecr" | ||
end | ||
|
||
Kemal.run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require "kemal" | ||
|
||
get "/" do | ||
form("") | ||
end | ||
|
||
post "/" do |env| | ||
response = "" | ||
text = env.params.body["text"]? | ||
if !text.nil? | ||
response = "You typed in <b>#{text}</b>" | ||
end | ||
form(response) | ||
end | ||
|
||
def form(response) | ||
%{ | ||
<form method="POST" action="/"> | ||
<input name="text"> | ||
<input type="submit" value="Echo"> | ||
</form> | ||
#{response} | ||
} | ||
end | ||
|
||
Kemal.run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require "kemal" | ||
|
||
get "/" do | ||
%{ | ||
<a href="/user/foo">/user/foo</a><br> | ||
<a href="/user/bar/bados">/user/bar/bados</a><br> | ||
<a href="/user/a/b/c">/user/a/b/c</a><br> | ||
<a href="/path/a/b/c/d">/path/a/b/c/d</a></br> | ||
} | ||
end | ||
|
||
get "/user/:fname" do |env| | ||
fname = env.params.url["fname"] | ||
"received fname: #{fname}" | ||
end | ||
|
||
get "/user/:fname/:lname" do |env| | ||
fname = env.params.url["fname"] | ||
lname = env.params.url["lname"] | ||
"received fname: #{fname} and lname: #{lname}" | ||
end | ||
|
||
get "/path/*all" do |env| | ||
all = env.params.url["all"] | ||
"received #{all}" | ||
end | ||
|
||
Kemal.run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=yes"> | ||
<title><%= title %></title> | ||
</head> | ||
<body> | ||
<%= content %> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<form method="GET" action="/"> | ||
<input name="text"> | ||
<input type="submit" value="Echo"> | ||
</form> | ||
<% if response %> | ||
You typed in <b><%= response %></b> | ||
<% end %> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters