0

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)?

Manu Chadha
  • 15,555
  • 19
  • 91
  • 184
  • You should only have one question per post (See https://meta.stackexchange.com/questions/222735/can-i-ask-only-one-question-per-post), I've answered your first one. Can you break the second one out into a separate question please? – Ruaidhrí Primrose Aug 03 '17 at 10:03

1 Answers1

2

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.

Ruaidhrí Primrose
  • 1,250
  • 1
  • 17
  • 22
  • thanks. Made this change `def hello2: ServiceCall[NotUsed, String]` and following worked `http://localhost:9000/hello2` – Manu Chadha Aug 03 '17 at 10:38