1. Technology
Send to a Friend via Email
You can opt-out at any time. Please refer to our privacy policy for contact information.

Deciding on Routing and Requests


You now have to decide how you'll want to name your routes and how information will be submitted from forms. A reasonable scheme would be to display forms with GET requests to /tool-name, and to run the tool with POST requests to /tool-name. Avoiding large, scary URLs with numerous GET parameters would be preferable. Though, the disadvantage of using POST requests is you cannot link to a POST request. You can't say "Hey Bob, Google is down, see? http://net.tools/ping/google.com."

As a starting point, I roughed out the following actions. Each corresponds to a different function. The GET handlers display the forms, and the POST requests run the tools.

At this point, I've also gone ahead and linked to the tools from the index page as well.

#!/usr/bin/env ruby
require 'rubygems'
require 'sinatra'
require 'haml'

get '/' do
  haml :index

# whois
get '/whois' do
  haml :whois

post '/whois' do
  haml :whois

# traceroute
get '/traceroute' do
  haml :traceroute

post '/traceroute' do
  haml :traceroute

@@ layout
    %title Network Tools
      %h1 Network Tools
    %a(href='/') Back to index

@@ index
  Welcome to Network Tools. Below is a list
  of the tools available.
      %a(href='/whois') Whois
      %a(href='/traceroute') Traceroute

@@ whois
%h3 Whois

@@ traceroute
%h3 Traceroute
  1. About.com
  2. Technology
  3. Ruby
  4. Tutorials
  5. Sinatra
  6. Deciding on Routing and Requests

©2014 About.com. All rights reserved.