The simplest thing that could possibly work: a service with a single call
-
Ensure you have Java 8 and Maven 3.3.1 or later installed.
-
Clone this project:
git clone https://github.com/TimMoore/lagom-minimal-helloworld.git
-
Enter the directory:
cd lagom-minimal-helloworld
-
Start the Lagom development environment:
mvn lagom:runAll
-
Wait until you see these lines in the console:
17:38:37.264 [info] play.api.Play [] - Application started (Dev) [INFO] Service hello-impl listening for HTTP on 0:0:0:0:0:0:0:0:57797 [INFO] (Service started, press enter to stop and go back to the console...)
-
Open a new terminal tab and use
curl
to exercise the service:$ curl http://localhost:9000/hello/Alice Hello, Alice! $ curl http://localhost:9000/hello/Bob Hello, Bob! $ curl http://localhost:9000/hello/Carol Hello, Carol!
The names aren't hard-coded, you can use anything you want in the last URL component.
You can also test it in your web browser with the same URL pattern.
-
In the first terminal, press
enter
to exit the Lagom development environment.
mvn test
This runs HelloServiceTest
using JUnit.
mvn package
This creates a zip file at hello-impl/target/hello-impl-1.0-SNAPSHOT-production-dist.zip
.
$ cd /tmp # or anywhere
$ unzip lagom-minimal-helloworld/hello-impl/target/hello-impl-1.0-SNAPSHOT-production-dist.zip # using the path to the directory where you cloned the project
cd hello
$ bin/start -Dplay.http.secret.key=xxxxx # you can set this value to whatever you want... Play requires it but Lagom doesn't use it
$ curl http://localhost:9000/hello/World
Hello, World!
# Interact with it as much as you want, then...
bin/stop # shut down the running server
Lagom requires a ServiceLocator
to be specified in production, but in this service it is never used.
This is handled in ConfigurationServiceLocatorModule
, where it binds a ConfigurationServiceLocator
. This implementation reads service locations from application.conf
, but since this service does not communicate externally, no services need to be configured.
See Lagom Production Overview for details.