Xitrum 2.0

36 views
Skip to first unread message

Ngoc Dao

unread,
Apr 14, 2013, 6:55:35 AM4/14/13
to Xitrum web framework
I've just released Xitrum 2.0:
https://github.com/ngocdaothanh/xitrum/blob/master/CHANGELOG

It's a major line. The biggest difference from Xitrum 1.x:
* In Xitrum 1.x, actions are grouped into controller classes.
* In Xitrum 2.x, actions are out to separate classes.

Each can be an Action (like before) or an ActionActor; your action can
be an actor. Ex:
https://github.com/ngocdaothanh/xitrum-demos/blob/master/src/main/scala/demos/action/ActionActorDemo.scala

You can annotate your Akka actors to make them accessible from web!

To update your app from Xitrum 1.22 to 2.0, see the diff of:
* xitrum-new: https://github.com/ngocdaothanh/xitrum-new/commit/2ecacd32cb97c2cab2c366ef170977863c24df8e
* xitrum-demos: https://github.com/ngocdaothanh/xitrum-demos/commit/17df23f3b979b6a0f9341c812ccf06af325229ea

Александр Гурьянов

unread,
Apr 14, 2013, 10:41:29 AM4/14/13
to xitrum-f...@googlegroups.com
Please explain advantages of new approach when each route is a concrete class. Why this is better than route per method. I feel non-comfortable with new scheme.

In xitrum 2.0 i should write more code to implement new route.

@GET("articles")
class ArticlesIndex {
  def execute() {
    respondView()
  }
}

def articles = GET("articles") {
respondView()
}

6 lines vs 3 lines

Ngoc Dao

unread,
Apr 14, 2013, 7:50:54 PM4/14/13
to Xitrum web framework
I've just released Xitrum 2.1:
* One bug fix: https://github.com/ngocdaothanh/xitrum/issues/110
* One improvement: https://github.com/ngocdaothanh/xitrum/issues/111

4 sample snippets have been added to the home page (please refresh
your browser):
http://ngocdaothanh.github.io/xitrum/

> Please explain advantages of new approach when each route is a concrete
> class. Why this is better than route per method. I feel non-comfortable
> with new scheme.

I feel that too. But this is a tradeoff to add support for routing to
Akka actors (see 3 of the 4 sample snippets above). Akka actors are
more comfortable/natural with classes.

Александр Гурьянов

unread,
Apr 14, 2013, 9:45:23 PM4/14/13
to xitrum-f...@googlegroups.com
Also i think annotations is not good enough for web-frameworks (it is less flexible then combing chain of function). I xitrum 1.22 i can implement something like this:

trait APIController extends Controller {
  def API_GET(pattern: String)(body: => AnyRef) = GET(s"$pattern/:respondType") {
    val respondType = paramo("respondType").getOrElse("json")
    //...
           respondType match {
      case "" =>
        respondJson(body)
      case "json" =>
        respondJson(body)
      case "jsonp" =>
        respondJsonP(body, callback)
      case "xml" =>
        respondXml(<error>Not supported for now</error>)
      case _ =>
        respondJson(new APIError(s"Respond type '$respondType' not supported"))
    }
   }
}

class API extends Contorller {
  def users = API_GET("users") {
     Users.findAll();
  }
}

How to do this In xitrum 2.0?

@GET("users:/respondType")
class APIUsers {
    around {
       API.wrap(action(), param('respondType'));
    }

   def execute() {
     User.findAll();
   }
}

With annoations making own request handler is harder or i miss something?

Ngoc Dao

unread,
Apr 15, 2013, 1:45:22 AM4/15/13
to Xitrum web framework
Your code is brilliant.

Yes in Xitrum 2 instead of letting Xitrum collect the separate routes
for you, you can use one "catch all" route
@GET(":pattern/:respondType"), around filter, and forwardTo.

Mohammad Bhuyan

unread,
Apr 18, 2013, 7:27:57 PM4/18/13
to xitrum-f...@googlegroups.com
I guess this is a breaking change? I need to update my Controllers/Actions to conform to new action approach? 

Ngoc Dao

unread,
Apr 18, 2013, 8:24:16 PM4/18/13
to Xitrum web framework

Yes, but basically you only needs to convert each actions inside controllers to a class.

--
You received this message because you are subscribed to the Google Groups "Xitrum web framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xitrum-framewo...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply all
Reply to author
Forward
0 new messages