This appendix covers how to download, run, use and load test Play.
You will need a JDK 1.8 that is more recent than b20. You can download the JDK from here.
You will need to have git installed.
You can clone the example project from GitHub:
git clone https://github.com/playframework/play-samples.git cd play-samples/play-scala-rest-api-example
You need to download and install sbt for this application to run. You can do that by going to the sbt download page and following the instructions for your platform.
Once you have sbt installed, the following at the command prompt will download any required library dependencies, and start up Play in development mode:
Play will start up on the HTTP port at http://localhost:9000/. You don’t need to deploy or reload anything – changing any source code while the server is running will automatically recompile and hot-reload the application on the next HTTP request. You can read more about using Play here.
If you call the same URL from the command line, you’ll see JSON. Using httpie, we can execute the command:
http --verbose http://localhost:9000/v1/posts
And get back:
GET /v1/posts HTTP/1.1
Likewise, you can also send a POST directly as JSON:
http --verbose POST http://localhost:9000/v1/posts title="hello" body="world"
POST /v1/posts HTTP/1.1
The best way to see what Play can do is to run a load test. We’ve included Gatling in this test project for integrated load testing.
Start Play in production mode, by staging the application and running the play scripts:
sbt stage ./target/universal/stage/bin/play-scala-rest-api-example -Dplay.http.secret.key=testing
Then you’ll start the Gatling load test up (it’s already integrated into the project):
For best results, start the gatling load test up on another machine so you do not have contending resources. You can edit the Gatling simulation, and change the numbers as appropriate.
Once the test completes, you’ll see an HTML file containing the load test chart:
That will contain your load test results.