Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Basic Sinatra routes (See related posts)

In the following example the routes can determine if the URI is an alias, a file, a directory, or is the root path.
#!/usr/bin/ruby  

# file: test.rb

require 'sinatra'


get '/' do
  "home"
end

get '/:file*.*' do
  "file"
end

get '/:alias' do
  "alias"
end

get '/:directory/' do  
  "directory"
end



Tested (http://niko:4567) observed
----------------------- --------
/README alias
/README/ directory
/README/fun.txt file
/fun alias
/ home
/home.txt file
/home.txt/ file
/home/file.txt file
/home/f Sinatra doesn't know this ditty
/home/ directory
/home?edit=1 alias
/home/?edit=1 directory
/home.xml?edit=1 file


Note: Alias in this context means a URI which will be redirected to another URI

Resources:
- Sinatra: README [sinatrarb.com]

You need to create an account or log in to post comments to this site.


Click here to browse all 7716 code snippets

Related Posts