Difference between pathCall and restCall

431 views
Skip to first unread message

heapi...@gmail.com

unread,
Apr 27, 2016, 9:10:17 AM4/27/16
to Lagom Framework Users
Hi,

from reading the documentation and looking at the example projects I am left a bit confused about what the difference is between pathCall and restCall; besides the fact that I can explicitly define the http method in restCall, whereas the http method seems to be determined automagically (based on the ServiceCall parameters) when using pathCall.

E.g. the chirper example has:

ServiceCall<String, Chirp, NotUsed> addChirp();

...

pathCall
("/api/chirps/live/:userId", addChirp()),

and this is called with a HTTP POST from the react-client.

If I understand correctly, one could have also written:

restCall(Method.POST, "/api/chirps/live/:userId", addChirp()),

So I saved a bit of typing but the code is also a bit more obscure because the reader has to deduce that pathCall will be mapped to a POST, based on the ServiceCall having a Request parameter != NotUsed. 

Is this "analysis" correct?
Could anyone shed some light on the differences between pathCall and restCall? And when one should prefer one over the other?

Thanks in advance.

James Roper

unread,
Apr 27, 2016, 10:13:49 PM4/27/16
to heapi...@gmail.com, Lagom Framework Users
Hi,

The idea is that you should use "pathCall" or "namedCall" when you don't care how this maps down to the underlying wire transport, but use "restCall" when you want it mapped down to specific REST methods/uris.  Lagom attempts to not be specific to REST, it should be possible in future to sub in other remote communication protocols, but in those contexts, defining an HTTP method and URI for every call is not only not necessary, it may not be able to be translated at all.  So, if you specifically want to write a REST interface to ensure that other REST clients can consume it, then use restCall, but be aware that's going to create a strong coupling in your application to REST and may limit you in future, if you want to be more flexible in your communication protocols and be able to take advantage of other protocols that we may support in future, then use namedCall or pathCall.  When you use namedCall or pathCall, and Lagom does map it down to REST, Lagom will make a best effort attempt to map it down to REST in a semantic fashion, so that means if there is a request message, it will use POST, if there's none, it will use GET.

Cheers,

James

--
You received this message because you are subscribed to the Google Groups "Lagom Framework Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lagom-framewo...@googlegroups.com.
To post to this group, send email to lagom-f...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lagom-framework/1aa2b50c-f33e-48ee-966c-473718e38939%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
James Roper
Software Engineer

Lightbend – Build reactive apps!
Twitter: @jroper

heapi...@gmail.com

unread,
Apr 28, 2016, 5:55:16 AM4/28/16
to Lagom Framework Users, heapi...@gmail.com
Ah ok, thanks for the explanation.
Mabye it would be helpful for others to include it in the documentation - maybe as an introduction to http://www.lagomframework.com/documentation/1.0.x/ServiceDescriptors.html#Call-identifiers - in case it is not already in there.
Reply all
Reply to author
Forward
0 new messages