Creating a prototype of play's controller and action to help understand scala












1















I'm confused as to how the request object can be injected into the Action.



Was hoping someone could create a simple prototype of the following in scala:



class HomeController() extends AbstractController {
def index() = Action { request =>
Ok("hello")
}
}


What I mean is, create the above classes/functions to simple return a string "hello", with the ability to get other objects in scope like "request".



abstract class AbstractController()
case class Action(???)
case class Ok(????)


I am just confused has to how you can create an Action {} and then have request available in the block specifically.










share|improve this question























  • It could be suggested to first have a look at the various tutorial available around the web about loan pattern and higher order functions

    – cchantep
    Jan 1 at 19:20
















1















I'm confused as to how the request object can be injected into the Action.



Was hoping someone could create a simple prototype of the following in scala:



class HomeController() extends AbstractController {
def index() = Action { request =>
Ok("hello")
}
}


What I mean is, create the above classes/functions to simple return a string "hello", with the ability to get other objects in scope like "request".



abstract class AbstractController()
case class Action(???)
case class Ok(????)


I am just confused has to how you can create an Action {} and then have request available in the block specifically.










share|improve this question























  • It could be suggested to first have a look at the various tutorial available around the web about loan pattern and higher order functions

    – cchantep
    Jan 1 at 19:20














1












1








1








I'm confused as to how the request object can be injected into the Action.



Was hoping someone could create a simple prototype of the following in scala:



class HomeController() extends AbstractController {
def index() = Action { request =>
Ok("hello")
}
}


What I mean is, create the above classes/functions to simple return a string "hello", with the ability to get other objects in scope like "request".



abstract class AbstractController()
case class Action(???)
case class Ok(????)


I am just confused has to how you can create an Action {} and then have request available in the block specifically.










share|improve this question














I'm confused as to how the request object can be injected into the Action.



Was hoping someone could create a simple prototype of the following in scala:



class HomeController() extends AbstractController {
def index() = Action { request =>
Ok("hello")
}
}


What I mean is, create the above classes/functions to simple return a string "hello", with the ability to get other objects in scope like "request".



abstract class AbstractController()
case class Action(???)
case class Ok(????)


I am just confused has to how you can create an Action {} and then have request available in the block specifically.







scala






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 1 at 18:21









BlankmanBlankman

97.8k2706641043




97.8k2706641043













  • It could be suggested to first have a look at the various tutorial available around the web about loan pattern and higher order functions

    – cchantep
    Jan 1 at 19:20



















  • It could be suggested to first have a look at the various tutorial available around the web about loan pattern and higher order functions

    – cchantep
    Jan 1 at 19:20

















It could be suggested to first have a look at the various tutorial available around the web about loan pattern and higher order functions

– cchantep
Jan 1 at 19:20





It could be suggested to first have a look at the various tutorial available around the web about loan pattern and higher order functions

– cchantep
Jan 1 at 19:20












1 Answer
1






active

oldest

votes


















1














If you write Action { request => ??? }, you're calling the apply method in the Action companion object. This method takes one parameter which is a function that takes a request and returns a response. The request value is the parameter of the function that you pass to the apply method.



Here's the method that you're calling.



If you would write a class like Action yourself, it may look similar to this:



case class Action(f: Request => Ok)





share|improve this answer


























  • The scaladoc permalink that I posted should point to the method apply(block: (R[B]) ⇒ Result): Action[B] , but scaladoc permalinks seems to be a little broken...

    – Aki
    Jan 1 at 18:43













  • Thanks, but I am looking for a complete example to get my mind to grasp this concept. It is still a little abstract in my mind.

    – Blankman
    Jan 2 at 21:38











  • Does this help: scastie.scala-lang.org/cizN7sDLT2mXzaDrvuQPXg

    – Aki
    Jan 2 at 23:32













  • that is perfect! Can you break down what this is in detail please case class Action(f: Request => Ok) the parameter is f, which is a function who's input is a of type Request and returns type OK right? is this passed by name style?

    – Blankman
    Jan 3 at 3:50











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53997841%2fcreating-a-prototype-of-plays-controller-and-action-to-help-understand-scala%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














If you write Action { request => ??? }, you're calling the apply method in the Action companion object. This method takes one parameter which is a function that takes a request and returns a response. The request value is the parameter of the function that you pass to the apply method.



Here's the method that you're calling.



If you would write a class like Action yourself, it may look similar to this:



case class Action(f: Request => Ok)





share|improve this answer


























  • The scaladoc permalink that I posted should point to the method apply(block: (R[B]) ⇒ Result): Action[B] , but scaladoc permalinks seems to be a little broken...

    – Aki
    Jan 1 at 18:43













  • Thanks, but I am looking for a complete example to get my mind to grasp this concept. It is still a little abstract in my mind.

    – Blankman
    Jan 2 at 21:38











  • Does this help: scastie.scala-lang.org/cizN7sDLT2mXzaDrvuQPXg

    – Aki
    Jan 2 at 23:32













  • that is perfect! Can you break down what this is in detail please case class Action(f: Request => Ok) the parameter is f, which is a function who's input is a of type Request and returns type OK right? is this passed by name style?

    – Blankman
    Jan 3 at 3:50
















1














If you write Action { request => ??? }, you're calling the apply method in the Action companion object. This method takes one parameter which is a function that takes a request and returns a response. The request value is the parameter of the function that you pass to the apply method.



Here's the method that you're calling.



If you would write a class like Action yourself, it may look similar to this:



case class Action(f: Request => Ok)





share|improve this answer


























  • The scaladoc permalink that I posted should point to the method apply(block: (R[B]) ⇒ Result): Action[B] , but scaladoc permalinks seems to be a little broken...

    – Aki
    Jan 1 at 18:43













  • Thanks, but I am looking for a complete example to get my mind to grasp this concept. It is still a little abstract in my mind.

    – Blankman
    Jan 2 at 21:38











  • Does this help: scastie.scala-lang.org/cizN7sDLT2mXzaDrvuQPXg

    – Aki
    Jan 2 at 23:32













  • that is perfect! Can you break down what this is in detail please case class Action(f: Request => Ok) the parameter is f, which is a function who's input is a of type Request and returns type OK right? is this passed by name style?

    – Blankman
    Jan 3 at 3:50














1












1








1







If you write Action { request => ??? }, you're calling the apply method in the Action companion object. This method takes one parameter which is a function that takes a request and returns a response. The request value is the parameter of the function that you pass to the apply method.



Here's the method that you're calling.



If you would write a class like Action yourself, it may look similar to this:



case class Action(f: Request => Ok)





share|improve this answer















If you write Action { request => ??? }, you're calling the apply method in the Action companion object. This method takes one parameter which is a function that takes a request and returns a response. The request value is the parameter of the function that you pass to the apply method.



Here's the method that you're calling.



If you would write a class like Action yourself, it may look similar to this:



case class Action(f: Request => Ok)






share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 1 at 18:44

























answered Jan 1 at 18:39









AkiAki

1,098214




1,098214













  • The scaladoc permalink that I posted should point to the method apply(block: (R[B]) ⇒ Result): Action[B] , but scaladoc permalinks seems to be a little broken...

    – Aki
    Jan 1 at 18:43













  • Thanks, but I am looking for a complete example to get my mind to grasp this concept. It is still a little abstract in my mind.

    – Blankman
    Jan 2 at 21:38











  • Does this help: scastie.scala-lang.org/cizN7sDLT2mXzaDrvuQPXg

    – Aki
    Jan 2 at 23:32













  • that is perfect! Can you break down what this is in detail please case class Action(f: Request => Ok) the parameter is f, which is a function who's input is a of type Request and returns type OK right? is this passed by name style?

    – Blankman
    Jan 3 at 3:50



















  • The scaladoc permalink that I posted should point to the method apply(block: (R[B]) ⇒ Result): Action[B] , but scaladoc permalinks seems to be a little broken...

    – Aki
    Jan 1 at 18:43













  • Thanks, but I am looking for a complete example to get my mind to grasp this concept. It is still a little abstract in my mind.

    – Blankman
    Jan 2 at 21:38











  • Does this help: scastie.scala-lang.org/cizN7sDLT2mXzaDrvuQPXg

    – Aki
    Jan 2 at 23:32













  • that is perfect! Can you break down what this is in detail please case class Action(f: Request => Ok) the parameter is f, which is a function who's input is a of type Request and returns type OK right? is this passed by name style?

    – Blankman
    Jan 3 at 3:50

















The scaladoc permalink that I posted should point to the method apply(block: (R[B]) ⇒ Result): Action[B] , but scaladoc permalinks seems to be a little broken...

– Aki
Jan 1 at 18:43







The scaladoc permalink that I posted should point to the method apply(block: (R[B]) ⇒ Result): Action[B] , but scaladoc permalinks seems to be a little broken...

– Aki
Jan 1 at 18:43















Thanks, but I am looking for a complete example to get my mind to grasp this concept. It is still a little abstract in my mind.

– Blankman
Jan 2 at 21:38





Thanks, but I am looking for a complete example to get my mind to grasp this concept. It is still a little abstract in my mind.

– Blankman
Jan 2 at 21:38













Does this help: scastie.scala-lang.org/cizN7sDLT2mXzaDrvuQPXg

– Aki
Jan 2 at 23:32







Does this help: scastie.scala-lang.org/cizN7sDLT2mXzaDrvuQPXg

– Aki
Jan 2 at 23:32















that is perfect! Can you break down what this is in detail please case class Action(f: Request => Ok) the parameter is f, which is a function who's input is a of type Request and returns type OK right? is this passed by name style?

– Blankman
Jan 3 at 3:50





that is perfect! Can you break down what this is in detail please case class Action(f: Request => Ok) the parameter is f, which is a function who's input is a of type Request and returns type OK right? is this passed by name style?

– Blankman
Jan 3 at 3:50




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53997841%2fcreating-a-prototype-of-plays-controller-and-action-to-help-understand-scala%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

Npm cannot find a required file even through it is in the searched directory