Skip to content

Instantly share code, notes, and snippets.

@d6y
Created June 30, 2013 17:16
Show Gist options
  • Select an option

  • Save d6y/5896016 to your computer and use it in GitHub Desktop.

Select an option

Save d6y/5896016 to your computer and use it in GitHub Desktop.
package code.rest
import net.liftweb.http.rest.RestHelper
import net.liftweb.json.JsonDSL._
import net.liftweb.json.JsonAST._
object PoemResource extends RestHelper {
// The database of poem titles:
val poems = Map(
"Larkin" -> List("This Be The Verse", "Aubade")
)
// Helper to convert from titles to a JSON representation:
def asJSON(titles: List[String]) : JValue =
("titles" -> titles)
// Match on a request, return a LiftResponse:
serve {
case "poems" :: "by" :: author :: Nil Get request =>
poems.get(author).map(asJSON)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment