在我的Play Scala应用程序中,我需要重用Controller Action代码(实际上是路径文件中定义的REST API):
conf / routes文件:
POST /saveuserdata controllers.thirdpartyapi.SaveUserDataController.saveUserData
SaveUserDataController.scala:
class SaveUserDataController extends Controller {
def saveUserData = Action.async {
//code which call a third party API (using WS) and returns Ok
//or InternalServerError
}
}
ApplicationTimer.scala:
val onceCancellable: Cancellable = system.scheduler.scheduleOnce(0.seconds) {
//call above Action method here and test for return status code
if (status == 200) {
println("Success: API returned 200 OK")
} else {
println("Failure: API returned failure status")
}
onceCancellable.cancel()
}
如何从其他地方调用控制器Action方法?