Bower integration in play

If you want to use a package.json in your play application add

  • the webjars dependency
  • a package.json in root
  • and the following in sbt , so you can access the javascript libraries.
val bowerPath = SettingKey[String]("bower-path", "where bower is installed")

lazy val bowerGenerateTaskImpl: Def.Initialize[Task[Seq[File]]] = (bowerPath,
                                                                   baseDirectory,
                                                                   streams) map {
  (bower, base, s) =>
    try {
      Process("npm" :: "install" :: Nil) ! s.log
      Process(bower :: "install" :: "--allow-root" :: Nil, base) ! s.log
      s.log.info("Bower install finished")
    } catch {
      case e: java.io.IOException =>
        s.log.error(
          "Bower couldn't be found. Please set the configuration key 'SimpleBowerKeys.bowerPath' properly. " + e.getMessage)
    }
    Seq()
}

bowerPath := sys.props.getOrElse("pathBower", default = "bower")
lazy val bowerGen = taskKey[Seq[File]]("Run bower")
bowerGen := bowerGenerateTaskImpl.value

lazy val copyBower = TaskKey[Seq[File]]("copyRes")
copyBower := {
  streams.value.log("Copy bower_components to public folder")
  val source = baseDirectory.value / "bower_components"
  val dest   = baseDirectory.value / "public" / "bower_components"
  IO.copyDirectory(source, dest)
  Seq()
}

lazy val bower = taskKey[Seq[File]]("Run bower")
bower := Def.sequential(bowerGen, copyBower).value
sourceGenerators in Compile += bower.taskValue

Play Framework - Beginner Tutorial : How to handle a big json file in play ( more than 22 root variables)

It is not a good practice to have such a big json with many root variables. Nevertheless, we might need to call a rest api that will give a json like this

{
  "a1": ...,
  "a2" : ...,
  "a3" : ...,
  "a4" : ...,
  "a5" : ...,
  "a6" : ...,
  "a7" : ...,
  "a8" : ...,
  "a9" : ...,
  "a10" : ...,
  "a11" : ...,
  "a12" : ...,
  "a13" : ...,
  "a14" : ...,
  "a15" : ...,
  "a16" : ...,
  "a17" : ...,
  "a18" : ...,
  "a19" : ...,
  "a20" : ...,
  "a21": ...,
  "a22" : ...,
  "a23" : ...,
  "a24" : ...,
  ....
}

First approach

Since scala 2.11 we can have case class with more than 22 fields, so the following compiles.

[Read More]

Play Framework - Beginner Tutorial : Make a post request and save the form data in Mongodb

Before the tutorial 

You should :

Tutorial 

Youtube video

After the tutorial

You should be able to :

[Read More]

Libraries for Play Framework

Whenever I come I across a Play library I take a note of it here. This collection is neither complete nor have I used all of these libraries. It is mainly used as a point of reference if I want to find some functionality implemented in a Play library.

Akka

This is a simple Play 2.6 module, which allows you to manage akka jobs.

Cache

Play framework 2 cache plugin as an adapter to redis-server check also scala cache libraries

[Read More]