-
Notifications
You must be signed in to change notification settings - Fork 0
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
0 parents
commit 409be03
Showing
5 changed files
with
78 additions
and
0 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,8 @@ | ||
A sample application built with Sinatra featuring multiple GET/POST routes and examples on how to work with POST data. | ||
|
||
Assuming you have Ruby installed: | ||
- 'gem install sinatra' | ||
- 'gem install shotgun' | ||
|
||
Clone the repo and run: | ||
- 'shotgun frank.rb' |
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,49 @@ | ||
require 'rubygems' | ||
require 'sinatra' | ||
|
||
# Define not_found route if we want to avoid display the default | ||
# not_found do | ||
# halt 404, 'page not found!' | ||
# end | ||
|
||
# Begin GET routes | ||
get '/' do | ||
erb :home | ||
end | ||
|
||
get '/about' do | ||
"Frank is the man, what more do you need to know?" | ||
end | ||
|
||
get '/decrypt/:secret' do | ||
params[:secret].reverse | ||
end | ||
|
||
get '/form' do | ||
#load embedded ruby file from /views | ||
erb :form | ||
end | ||
|
||
get '/hello/:name/:city' do | ||
"Hello there, #{params[:name].capitalize} from #{params[:city]}." | ||
end | ||
|
||
get '/more/*' do | ||
#display all params passed to route | ||
params[:splat] | ||
end | ||
|
||
get '/reverse' do | ||
erb :reverse | ||
end | ||
#End GET routes | ||
|
||
#Begin POST routes | ||
post '/form' do | ||
"You said '#{params[:message]}'" | ||
end | ||
|
||
post '/reverse' do | ||
params[:secret].reverse | ||
end | ||
#End POST routes |
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,5 @@ | ||
<h3>Display POST</h3> | ||
<form action="/form" method="post"> | ||
<input type="text" name="message"> | ||
<input type="submit"> | ||
</form> |
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 @@ | ||
<h3>Sinatra Example</h3> | ||
<p> | ||
Available Routes: | ||
<ul> | ||
<li><a href="/about">About [Text]</a></li> | ||
<li><a href="/form">Form [POST Example]</a></li> | ||
<li><a href="/hello/niczak/Minneapolis">Hello [2 Params]</a></li> | ||
<li><a href="/more/foo/bar">More [Splat Example]</a></li> | ||
<li><a href="/reverse">Reverse [String Reversal]</a></li> | ||
</ul> | ||
</p> |
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,5 @@ | ||
<h3>String Reversal</h3> | ||
<form action="/reverse" method="post"> | ||
<input type="text" name="secret"> | ||
<input type="submit"> | ||
</form> |