MarcLoupias/poc-play-rest-backend


A Play! app to serve JSon REST services without serving any web page.

License: WTFPL

Language: Java

Keywords: java, mysql, play-framework, poc, rest-api


poc-play-rest-backend

Current [Play!] (http://www.playframework.com/) version is 2.2.1 (nov 2013)

WTFPL

What is this ?

A Play! app to serve JSon REST services without serving any web page. The app is configured for a MySQL db using JPA via Hibernate provider. We assume that a MySQL db is running on localhost in dev mode.

For what purpose ?

The main goal is to provide a full dev environment, a skeleton for a REST server, with some good practices for the most common problems encountered in that case.

I try to follow theses principles :

What is done and you can read or pick ?

Installation

  • You need a MySQL working installation. (Just create a new user for that app, check config, then run the app or the db-reset ant task.)
  • You need to install Play! version 2.2.1+. (That config will not work with an inferior version due to framework last changes.)

Running the application locally and play with it

  1. Enter in your project root directory in the console.
  2. Run the app with play run command. (play "run 8080" to run it on the 8080 port)
  3. Go to http://localhost:9000/version with your favourite browser.

To manually run the app without a front-end, i use the [RESTClient plugin] (https://addons.mozilla.org/fr/firefox/addon/restclient/) for Firefox. If you want install it, you can import some Rest requests from rest-client/poc-play-rest-backend-requests.json file. In RESTClient menu, "Favorite requests" -> "Import favorite requests".

Configurations files

  • Check database configuration in conf/application.conf.
  • Check conf/configure.sh to set up shell before launching Play! console.

IDE setup

This project is set for IntelliJ by [mpeltonen sbt plugin] (https://github.com/mpeltonen/sbt-idea) Open a play console then type gen-idea. A valid IntelliJ project will be set up, at this point you can open project in IntelliJ. Notices that each time you add a dependency in build.sbt file you need to execute gen-idea (no need to close IDEA).

Running tests

Unit tests uses [JUnit4] (http://junit.org/). Integration tests uses [RestAssured] (http://code.google.com/p/rest-assured/).

  • Tests can be run with the regular way through play console by typing play test.
  • Tests can be run manually with IntelliJ.
  • Tests can be run manually with IntelliJ via the run-tests-fullstack ant task to generate a html report in junit/reports/index.html.

Ant tasks

Tasks config are done on the top of build.xml file. You will need to update properties value for db access and play directory. See description of each tasks.

Version number management

We use [sbt-buildinfo plugin] (https://github.com/sbt/sbt-buildinfo). Version number is set in build.sbt in the Play! regular way. Open a play console then type reload to see changes. We follow [SemVer] (http://semver.org/) convention.

Heroku Deployment

Related project files :

  • scripts/heroku-deploy-sample.sh (to set up the env)
  • Procfile (to configure the process (the dyno in heroku world) running the app)
  • system.properties (to run the app under 1.7 JRE)

Some useful tips :

Some useful heroku shell commands (need to be in your source root directory) :

  • $ heroku create to create a new app. Name is auto-generated and can be changed in the dashboard settings panel.
  • $ heroku ps to list the running dynos.
  • $ heroku config to display your app config.
  • $ git push heroku master push your current git code to heroku. Heroku app are built from source code.
  • $ heroku ps:scale web=1 to run the app with only one dyno (free)
  • $ heroku logs > logs/heroku.log to get logs from heroku in your play logs dir locally.

Areas of improvements

  • I would like to get comments on this, of any kind.
  • I don't know how to run only unit tests without integration tests with Play! via Ant in a simple way.
  • I don't know how to rollback the database after each integration test without deleting each record used manually.
  • Transactions are functional but i have to work on [concurrency] (https://blogs.oracle.com/enterprisetechtips/entry/locking_and_concurrency_in_java).
  • I need also to work on continuous integration.

Project Statistics

Sourcerank 4
Repository Size 516 KB
Stars 8
Forks 2
Watchers 2
Open issues 0
Dependencies 0
Contributors 1
Tags 2
Created
Last updated
Last pushed

Top Contributors See all

marlou

Recent Tags See all

0.1.1 March 27, 2014
0.1.0 February 25, 2014

Something wrong with this page? Make a suggestion

Last synced: 2018-07-13 22:52:20 UTC

Login to resync this repository