I am experimenting with Lagom to check how call
, pathCall
and namedCall
are invoked. I am following lagom's tutorial. I created a new service and opened url using following urls but I get error
URL used (I expect to see hello2 response)
http://localhost:9000/
Error
GET\Q/stream\EService: hello-stream (http://0.0.0.0:58322)
2GET\Q/api/hello/\E([^/]+)Service: hello (http://0.0.0.0:57797)
3POST\Q/api/hello/\E([^/]+)Service: hello (http://0.0.0.0:57797)
**4POST\Q/hello2\EService: hello (http://0.0.0.0:57797)**
I have done following steps
After downloading template (see https://www.lagomframework.com/documentation/1.3.x/scala/IntroGetStarted.html), I have changed the code to add a new service call (called hello2). Following is teh code I have added in HelloService.scala
named("hello")
.withCalls(
pathCall("/api/hello/:id", hello _),
pathCall("/api/hello/:id", useGreeting _),
call(hello2) //added this line in default template.
)
I have defined hello2 as (in HelloService.scala)
def hello2: ServiceCall[String, String]
The code in HelloServiceImpl.scala is
override def hello2 = ServiceCall {
Future.successful("Hello2")
}
Questin 1 - What is the mistake (I guess I am not invoking the service correctly from the browser)?
When you say, "I guess I am not invoking the service correctly from the browser", do you mean you're just navigating to the URL in your browser? If so, this won't work because hello2 is defined as a POST endpoint and your browser will be sending a GET request.
hello2 is defined as a POST endpoint because in your ServiceCall definition it takes a request message. (See https://www.lagomframework.com/documentation/1.3.x/java/ServiceDescriptors.html for more info.)
If you change the request message type from String
to NotUsed
then Lagom should start generating a GET endpoint instead.