How to get payload from a POST in Play 2.0

前端 未结 4 559
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-07 22:16

I\'m trying to implement a REST API with Play 2.0 (Scala) but I\'m getting stuck in POST method. How do I get the payload from Request object? I haven\'t find any documentation

4条回答
  •  無奈伤痛
    2021-02-07 22:50

    You should be able to do the following:

    def index = Action { request =>
      val body = request.body
    }
    

    And also things like:

    def index = Action { request =>
      val name = request.queryString.get("name").flatMap(_.headOption)
      Ok("Hello " + name.getOrElse("Guest"))
    }
    

提交回复
热议问题