Visar inlägg med etikett backend. Visa alla inlägg
Visar inlägg med etikett backend. Visa alla inlägg

2016-04-02

Webapp with HTML, CSS and JavaScript written in Scala

ISO Scala

This is an example of HTML, CSS and JavaScript written in Scala.

Technics

Different parts are written in different ways
  • Backend, Scala implementation of a Java Servlet
  • HTML and CSS, using ScalaTags to generate HTML in a String
  • JavaScript, built with ScalaJS

Two Builds

There are two different builds
  1. Backend, using plain Maven to build and setup the project
  2. JavaScript, built with SBT and using ScalaJS dependencies

Example

View a whole example at

2015-12-05

Dynamic and facade implementation of Google Endpoints with Scala JS

Google Endpoints generates Javascript that mirrors all REST calls to backend. With Scala JS, these scripts can be used in two different ways: dynamic or facade.

Dynamic

This is the easiest solution. If you know the names and the parameters to backend I would recomend this approch. All you need to do is to type vars and defs to js.Dynamic and then use them just as Javascript. Example of loading your API:
And to use a method with csv as parameter:
"literal(csv = validatedText)" is like Javascript "{csv : validatedText}"

Facade

This is approch needs more work since you need to mirror the Javascript generated by Google Endpoints, but will give you types and the structure of the Javascript.
Example of loading your API:
This works since you have defined the API in a facade like in this example:
You know which functions are available since you have made a complete facade. Example:
And therefore it's easy make a call with types:

2015-12-04

Scala JS with Angular and Google Endpoints

Finally done with a simple implementation with Scala JS of Angular and Google Endpoints.

Scala

All backend and frontend is done in Scala with shared logic. Made a simple validation of input which is used in frontend when trying to post, and in backend when it receives.

Google Endpoints

A Javascript is generated which mirrors all exposed methods. This is then used by Scala JS to make all requests to backend.

2015-09-02

Scala JS Target Folder

Scala JS: Set Target Folder for JavaScript Build

Recently I've been interested in  Scala JS. It would be great to share logic on client and server side and to write all code in Scala. But SBT can be a bit tricky and my project setup was divided into two:

  1. One webapp with a Java web container
  2. Scala JS with logic shared between frontend and backend
To get SBT to build the JavaScript from my Scala JS project to my webapp I needed to add the following lines in my root build.sbt file:

val jsDir = "../gae/src/main/webapp"
crossTarget in (Compile, fastOptJS) := file(jsDir)

Project combining Scala JS and Java web container

You can check out my project which uses this build at