Typesafe Activator

ReactiveMongo Play Autosource

ReactiveMongo Play Autosource

mandubian
Source
July 16, 2013
meta-template

A template for ReactiveMongo Play Autosource - Automatic CRUD/REST Datasource.

How to get "ReactiveMongo Play Autosource" on your computer

There are several ways to get this template.

Option 1: Choose activator-play-autosource-reactivemongo in the Typesafe Activator UI.

Already have Typesafe Activator (get it here)? Launch the UI then search for activator-play-autosource-reactivemongo in the list of templates.

Option 2: Download the activator-play-autosource-reactivemongo project as a zip archive

If you haven't installed Activator, you can get the code by downloading the template bundle for activator-play-autosource-reactivemongo.

  1. Download the Template Bundle for "ReactiveMongo Play Autosource"
  2. Extract the downloaded zip file to your system
  3. The bundle includes a small bootstrap script that can start Activator. To start Typesafe Activator's UI:

    In your File Explorer, navigate into the directory that the template was extracted to, right-click on the file named "activator.bat", then select "Open", and if prompted with a warning, click to continue:

    Or from a command line:

     C:\Users\typesafe\activator-play-autosource-reactivemongo> activator ui 
    This will start Typesafe Activator and open this template in your browser.

Option 3: Create a activator-play-autosource-reactivemongo project from the command line

If you have Typesafe Activator, use its command line mode to create a new project from this template. Type activator new PROJECTNAME activator-play-autosource-reactivemongo on the command line.

Option 4: View the template source

The creator of this template maintains it at https://github.com/mandubian/activator-play-autosource-reactivemongo.

Option 5: Preview the tutorial below

We've included the text of this template's tutorial below, but it may work better if you view it inside Activator on your computer. Activator tutorials are often designed to be interactive.

Preview the tutorial

You've just created a simple Play application providing a usable Play Autosource for ReactiveMongo.
With it, you can bootstrap in a few lines an automatic CRUD asynchronous datasource with REST endpoints back'ed on ReactiveMongo. It's quite useful to :

  • Kickstart an application and test your frontend
  • Build iteratively your models from blob to static (or just go on using blobs with some Json validations)
  • Expose your existing models as REST sources in a very few lines

The concept is explained more precisely in these articles:

Read these articles and look at code in app/Application.scala and conf/routes, it's quite explicit and provides everything to start.

To test it:

  1. Run a Mongo Server on your local computer
  2. Just run the application by launching classic sbt

Play-Autosource concept has been implemented for :


Maybe soon Activator's template for those Autosources...

Autosource Standard Routes

Get / Find / Stream

  • GET /persons?… -> Find by query
  • GET /persons/ID -> Find by ID
  • GET /persons/stream -> Find by query & stream result by page

Insert / Batch / Find

  • POST /persons + BODY -> Insert
  • POST /persons/find + BODY -> find by query (when query is too complex to be in a GET)
  • POST /persons/batch + BODY -> batch insert (multiple)

Update / batch

  • PUT /persons/ID + BODY -> Update by ID
  • PUT /persons/ID/partial + BODY -> Update partially by ID
  • PUT /persons/batch -> batch update (multiple)

Delete / Batch

  • DELETE /persons/ID -> delete by ID
  • DELETE /persons/batch + BODY -> batch delete (multiple)
comments powered by Disqus