2015-12-06

Infographic of Google Endpoints in both Scala and Scala JS

I'm no expert in infographics, but I'd tried to show how Google Endpoints is implemented in Scala and Scala JS.

Map

So there are three different languages:
  1. Scala
  2. Javascript
  3. HTML

Google Endpoints

When this is implemented in Scala on backend, it will generate Javascript. HTML needs to load the script and call a Javascript function when loaded.

Scala JS

Written in Scala, Scala JS will generate Javascript. When the Google Endpoints script is loaded, it will callback to Scala JS's script which will created either dynamic or facade representations of it.

Shared

Since Google Endpoints is implemented in Scala and frontend Javascripts in Scala JS, it's easy to share common logic with Scala code.

Code Example

A simple implementation can be found here:

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.