play

How to read/access Play Framework application.conf properties

Here’s a quick look at how to read Play Framework application.conf configuration properties.

First, given a Play application.conf file with these properties:

foo=42

bar.baz=10

stations = [ 99.5, 102.3, 104.3, 105.9 ]

streams = [
    { "name": "104.3", "file": "104_3.pls" },
    { "name": "WGN",   "file": "wgn.pls" }
]

You can read the foo property (as a String) from your Play code like this:

How to run Play Framework model methods from the Play console

Here’s a quick look at how to run Play Framework “model” methods from the Play console. In my case, my model methods are Anorm database access methods, but you may be accessing MongoDB, Cassandra, CouchDB, whatever.

First, move to your Play application directory and start the Play interpreter:

$ play

Then start the Play console:

[MyApp] $ console

Your prompt will now look like this:

A list of Play Framework controller action results (result types)

When you’re writing Play Framework controller actions, you’re typically going to be returning a Play Results, with the most common result being Ok. However, your controller actions can return many different result types. This table shows some of the most common result types that you can use instead of Ok: