Book Image

Play Framework essentials

By : Julien Richard-Foy
Book Image

Play Framework essentials

By: Julien Richard-Foy

Overview of this book

Table of Contents (14 chapters)
Play Framework Essentials
About the Author
About the Reviewers

Putting things together

You now have all the required knowledge to define HTTP endpoints for the list, create, and get entry points of the Shop service so that your HTTP endpoints can read both HTML form data and JSON data, and can return either HTML or JSON content according to the client's preferences.

For instance, here is the code for how the create endpoint can look like:

  val create = Action { implicit request =>
      formWithErrors => render {
        case Accepts.Html() =>
        case Accepts.Json() => BadRequest(formWithErrors.errorsAsJson)
      createItem => {
        shop.create(, createItem.price) match {
          case Some(item) => render {
            case Accepts.Html() => Redirect(routes.Items.details(
            case Accepts.Json() => Ok(Json.toJson(item))
          case None => InternalServerError...