Skip to content

Latest commit

 

History

History
95 lines (66 loc) · 2.63 KB

README.md

File metadata and controls

95 lines (66 loc) · 2.63 KB

Scalext

Build Status Coverage Status

Ext JS Driver for Play Framework 2.2.2

Features

  • Supports single or batched JSON requests
  • Automatic serialization and deserialization of Ext.Direct actions
  • Direct API configuration using annotations
  • DSL for creating Ext JS objects
  • Parallel execution of batched requests

Roadmap

  • Unit tests
  • Support for more frameworks
  • Expanding DSL

Getting started

Download the latest distributable jar here and put it in your lib folder

Add the classes from which you want to generate a Direct Api to conf/application.conf, for example:

scalext.direct.classes="direct.ProfileForm,direct.RegistrationForm,direct.EchoService"

Include the javascript file which generates the Direct Api inside a view:

<script type="text/javascript" src="@com.scalext.controllers.routes.Api.buildApi()"></script>

The Direct Api is now available!

Configuring the Direct API

Classes can be exposed to the Direct API by adding annotations to methods.

case class Profile(name: String, email: String, company: String)

@Remotable(name = "Scalext.example.Profile")
class Form {

  @Remotable
  def getBasicInfo(): FormResult = {
    var profile = Profile(
      "Roy van Kaathoven",
      "[email protected]",
      "Roy")

    FormResult(profile)
  }

  @FormHandler
  def updateBasicInfo(profile: Profile): FormResult = {
    FormResult(
      null,
      errors = Map("name" -> "wrong info"))
  }
}
@Remotable(name = "Scalext.example.Upload")
class Upload {

  @FormHandler
  def uploadFile(post: Any, files: Seq[TemporaryFile]): FormResult = {

    println("Post " + post)
    println("Files " + files)

    FormResult(Map("msg" -> s"${files.size} file(s) succesfully uploaded"))
  }

}

The @Remotable annotation marks a method as Direct Method, which means it will be exposed to the Direct API. By default the method- or classname will be used, this can be overridden by setting the name parameter.

The @FormHandler annotation marks a method as as Form submit handler, which means it can handle form submissions and even file uploads. If the method has to read file uploads then make sure the second parameter can handle the Seq[TemporaryFile] type.

Documentation