Skip to content

Step 8 pretify urls

opensas edited this page Nov 3, 2011 · 8 revisions

Step 8 - pretify urls

Purpose: in this step we will see how play helps us build human readeble and elegants urls.

cd ~/devel/apps
git clone git://github.com/opensas/play-demo.git
cd play-demo
git checkout origin/08-pretify_urls

See current urls

If you pay attention to our app, these are the current urls

add an event    -> GET       application/form
edit an event   -> GET       application/form?id=xxx
save changes    -> POST      application/save
delete an event -> DELETE    delete/xxx

We can do better than that! So open routes files and add the following routes:

conf/routes

# Home page
GET     /                               Application.list
GET     /events                         Application.list

GET     /edit/{id}                      Application.form
GET     /new                            Application.form

POST    /save                           Application.save

DELETE  /delete/{id}                    Application.delete

GET     /load                           Application.loadFromYaml

*       /admin                          module:crud

# Ignore favicon requests
GET     /favicon.ico                    404

# Map static resources from the /app/public folder to the /public path
GET     /public/                        staticDir:public

# Catch all
# *       /{controller}/{action}        {controller}.{action}

For security reasons, it is always a good advice to comment the catch all route when going in production.


Our site is ready, now we are going to Step 9 - authentication.