MrTugay
MrTugay

Reputation: 21

Play Scala Call Controller Method From Another Method

I have been using the Play Framework for Scala and Have Run Into Some Trouble.

I am trying to Call Another Controller Method From A Controller Method. At First I tried Using The WSRequest/Response To Call the Other Controller Method's Route however The WSResponse Contained Nothing! No Cookies or Header Even though the Controller's method would return a redirect WithCookies.

Also I AM not Sure How To Just Directly call The Controller Method Since It Returns a EssentialAction, But the First Method Uses the Implicit Request ActionAsync Method Which Require's a Future[Result]. How would I Use the EssentiaLAction to Make a Future[Result]!!?

Any Ideas On How to Fix MY PRoblem? THanks!

Upvotes: 1

Views: 1366

Answers (1)

andrey.ladniy
andrey.ladniy

Reputation: 1674

Based on Action composition

def a(s: String): Action[AnyContent] = Action.async {
  Future(Ok(s))
}

def b: Action[AnyContent] = Action.async {request =>
  a("from b")(request)
}

Upvotes: 2

Related Questions