       res.render '401', 401
     else
       next()
-  
 
-  app.all '/private', checkAuth, (req, res, next) ->
+  app.get '/private', checkAuth, (req, res, next) ->
     routeMVC('private', 'index', req, res, next)
   
-  #   - _/_ -> controllers/index/index method
-  app.all '/', (req, res, next) ->
+  # Front page
+  app.get '/', (req, res, next) ->
     routeMVC('index', 'index', req, res, next)
 
-  #   - _/**:controller**_  -> controllers/***:controller***/index method
-  app.all '/:controller', (req, res, next) ->
+  # Get resource items list
+  app.get '/:controller', (req, res, next) ->
     routeMVC(req.params.controller, 'index', req, res, next)
 
-  #   - _/**:controller**/**:method**_ -> controllers/***:controller***/***:method*** method
-  app.all '/:controller/:method', (req, res, next) ->
-    routeMVC(req.params.controller, req.params.method, req, res, next)
+  # Create new resource item
+  app.post '/:controller', (req, res, next) ->
+    routeMVC(req.params.controller, 'create', req, res, next)
 
-  #   - _/**:controller**/**:method**/**:id**_ -> controllers/***:controller***/***:method*** method with ***:id*** param passed
+  # Get resource item by id
+  app.get '/:controller/:id', (req, res, next) ->
+    routeMVC(req.params.controller, 'get', req, res, next)
+
+  # Update item data
+  app.put '/:controller/:id', (req, res, next) ->
+    routeMVC(req.params.controller, 'update', req, res, next)
+
+  # Remove resource instance
+  app.delete '/:controller/:id', (req, res, next) ->
+    routeMVC(req.params.controller, 'delete', req, res, next)
+
+  # Search method in controller with id
   app.all '/:controller/:method/:id', (req, res, next) ->
     routeMVC(req.params.controller, req.params.method, req, res, next)
 

#### Routes
# We are setting up theese routes:
#
# GET, POST, PUT, DELETE methods are going to the same controller methods - we dont care.
# We are using method names to determine controller actions for clearness.

module.exports = (app) ->
  

    res.statusCode = 404
    res.render '404', 404

# Render the page based on controller name, method and id
routeMVC = (controllerName, methodName, req, res, next) ->
  controllerName = 'index' if not controllerName?
  controller = null
  try
    controller = require './controllers/' + controllerName
  catch e
#    console.warn "controller not found: " + controllerName, e
    next()
