|
@@ -1,24 +1,24 @@
|
|
package controllers
|
|
package controllers
|
|
|
|
|
|
-import javax.inject.Singleton
|
|
|
|
-import akka.util.CompactByteString
|
|
|
|
-import play.api.http.HttpEntity.Strict
|
|
|
|
|
|
+import javax.inject.{ Inject, Singleton }
|
|
|
|
+
|
|
import play.api.mvc._
|
|
import play.api.mvc._
|
|
import play.api.libs.json.Json
|
|
import play.api.libs.json.Json
|
|
import play.mvc.Http
|
|
import play.mvc.Http
|
|
|
|
|
|
@Singleton
|
|
@Singleton
|
|
-class Application extends Controller {
|
|
|
|
- val header = ResponseHeader(OK, Map(Http.HeaderNames.SERVER -> "EXAMPLE"))
|
|
|
|
|
|
+class Application @Inject() (cc: ControllerComponents)
|
|
|
|
+extends AbstractController(cc) {
|
|
|
|
+
|
|
implicit val helloWorldWrites = Json.writes[HelloWorld]
|
|
implicit val helloWorldWrites = Json.writes[HelloWorld]
|
|
|
|
|
|
def getJsonMessage = Action {
|
|
def getJsonMessage = Action {
|
|
val helloWorld = HelloWorld(message = "Hello, World!")
|
|
val helloWorld = HelloWorld(message = "Hello, World!")
|
|
- Result(header, Strict(CompactByteString(Json.toJson(helloWorld).toString()), Some("application/json")))
|
|
|
|
|
|
+ Ok(Json.toJson(helloWorld)).withHeaders(Http.HeaderNames.SERVER -> "Play Framework")
|
|
}
|
|
}
|
|
|
|
|
|
val plaintext = Action {
|
|
val plaintext = Action {
|
|
- Result(header, Strict(CompactByteString("Hello, World!"), Some("text/plain")))
|
|
|
|
|
|
+ Ok("Hello, World!").withHeaders(Http.HeaderNames.SERVER -> "Play Framework")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|