Search code examples
ajaxscalaplayframeworkplayframework-2.2

What should I name the actions for ajax requests?


Let's say I have an action:

def result = Action { Ok(views.html.home.result()) }

From result view I want to send ajax requests to the server. What's the standard (if any) way to name the actions that receive such the ajax requests? It might be something like:

def getResultAjax(param1: Int) = //.... 

To my mind, it look clumsy.

Your ideas?


Solution

  • There's no such convention in Play, anyway action's name should rather contain info about returned data i.e. listOfBooks then just getResult.

    On the other hand when there's a lot of different methods (some common, other for ajax requests) it can be cleaner if you'll use ajaxListOfBooks or create BooksAjax controller to handle AJAX request only.

    BTW: Purists would say that the requests REST's HTTP methods should also be taken into account, and then action names can be simplified, pseudo routes:

    GET     /ajax/books       Books.list
    GET     /ajax/books/:id   Books.get(id)
    PUT     /ajax/books       Books.create
    POST    /ajax/books/:id   Books.update(id)