Is this correct way to handle RESTful like URL in Lift Framework?

If I have a URL like http://localhost/Test/edit/{id} and I would like the {id} transform to a parameter instead of URL path part.

Is it best way to do it by create a menu with RewriteRequest? Because I found it a little boilerplate if I have lot URL pattern like this.

val menu = Menu(new Loc[Unit] {

    override def name = "Test"
    override def text = "Test"
    override def link = (List ("Test"), true)
    override def params = Nil
    override def defaultValue = Full(())


    def isTarget (path: ParsePath) = path match {
        case ParsePath (List("Test", "edit", id), _, _, _) => true

        case _ => false
    }

    override def rewrite = Full ( NamedPF("Test") {
        case RewriteRequest (path, _, _) if isTarget(path) => 
             RewriteResponse(List("Test", "edit"),  
                             Map("id" -> "1024")) -> ()

    })
})

Answers


In your boot.scala you need the following (from actual working code!) Note that each RewriteResponse path must be in your sitemap.

LiftRules.rewrite.append {
  case RewriteRequest(ParsePath(List("shopInfo", "view", id), _, _, _), _, _) => RewriteResponse("shopInfo" :: "view" :: Nil, Map("id" -> id))
  case RewriteRequest(ParsePath(List("shopInfo", "orders", id), _, _, _), _, _) => RewriteResponse("shopInfo" :: "orders" :: Nil, Map("id" -> id))
  case RewriteRequest(ParsePath(List("shopInfo", "sync", id), _, _, _), _, _) => RewriteResponse("shopInfo" ::  "sync" :: Nil, Map("id" -> id))
  case RewriteRequest(ParsePath(List("shopInfo", "delete", id), _, _, _), _, _) => RewriteResponse("shopInfo" :: "delete" :: Nil, Map("id" -> id))
  case RewriteRequest(ParsePath(List("shopInfo", "edit", id), _, _, _), _, _) => RewriteResponse("shopInfo" :: "edit" :: Nil, Map("id" -> id))
}

Need Your Help

Nginx Reverse Proxying to Node.js with Rewrite

javascript node.js nginx express reverse-proxy

I have several apps running behind an Nginx reverse proxy, one of which is a Node server with Express.js. I'm proxying domain.com/demo/app/<path> to localhost:7003/<path> using this Nginx

Shuffle 12 <li> elements from <ul> excluding 3 elements from the list

javascript jquery html css

I would like to show from the list 12 &lt;li&gt; elements, shuffle them and keep the rest hidden. To did it I have used shuffle.js and it works perfectly, I used as well those few lines to hide the...