Giter Site home page Giter Site logo

scalext's Introduction

Scalext

Build Status Coverage Status

Ext JS Driver for Play Framework 2.1

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

scalext's People

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.