For some supernatural reasons, for half a year I have not been able to write this text, but I really want to talk about a new, almost unknown, in any case on the habre, the framework -
Prudence .
Prudence - written in java framework, which allows you to create an application on other PLs (javascript, php, python, etc.). In this article I will consider the possibility of working with server-side javascript. Unlike node.js, prudence works on the basis of the JVM engine, which allows using third-party java libraries. In addition, the application turns out to be cross-platform and works inside its “container”.

')
A year ago, there was very little documentation about prudence, and the developer Tal Liron advised to look at the sample applications as part of the framework. I will do the same in this way, having laid out the source codes of a simple application on
github , going over all the points: installation, configuration, development and launch of the application.
The task : to create an application that allows you to store certain objects in a tree structure and separately to each object allows you to add text data. In addition, the data from the client's browser (frontend) to the server (backend) and back must be transferred encrypted.
For the frontend, I’ll use Twitter Bootstrap and JS (again the framework) Kendo UI Web, because all the necessary widgets (treeview, htmleditor, tabstrip are in the GPL version, which, by the way, Teleric (developer of the Kendo UI framework) was hiding :(
For data storage in backend I will use
MongoDB . The code will be in JS, despite the fact that the framework allows writing in other languages.
To encrypt data between the client and the server, I will use the Stanford Javascript Crypto Library (http://bitwiseshiftleft.imtqy.com/sjcl/). The library is used in both Frontend and Backend. Post request data and response is encrypted accordingly.
On the client side, in order to encrypt each Ajax request, a “wrapper” is used:
encryptAjax(URL, DATA, function(res) {
//
});
Example client - server and server - client requests / responses:

Installation
You can install prudence by downloading the source code of the framework, but it’s better with the
sincerity utility.
Sincerity is a lightweight package manager that allows you to build (update) the required framework environment.
Download sincerity
here .
After installing sincerity in the system:
sincerity create myprudence : add prudence.admin : add mongovision : install
will create a “container” with all utilities needed to launch the application, where myprudence is the directory in which all the necessary file structure will be created.
The application source code is here:
\ component \ applications \ <application>Here
\ component \ templates \ default \ you can take templates for creating a new application.
The
default.js ,
routing.js and
settings.js files are basic for the project, their syntax can be found in the documentation, and an example in the project on
github .
Frontend
All files are located by default in the
resources directory. The main file should be called
index.t.html (with the suffix t). Paths to project files are specified relative to the
resources directory:
/>
/>
Backend
Since the application is small, one route is enough for us:
/ data / {action}To do this,
we add one line to
routing.js :
'/data/{action}/': '@app'
{action} can be obtained in the controller of our application -
conversation.locals.get ('action')Also in
routing.js the following entry is required:
app.dispatchers = {
javascript: '/resources/js/'
}
Where we indicate which programming language we use and the path to the file "dispatcher".
This file will be located here
/ resources / js / and it is called
default.js . It will need to connect the necessary controller files and call them. Since we specified '@app' in the routes, we will make the corresponding entry in the resources parameter:
document.executeOnce('/resources/js/app/')
resources = {
app: new AppResource()
}
The file
/resources/js/app.js will be our controller.
You can see the class itself in the example or read the documentation on how to create the simplest 'Hello world!' attachment.
In settings.js:
app.globals.sjcl = {
password: 'xxxx'
}
The password that must be entered in the "Login" field and click "Ok".
In the backend, it will be available as:
application.globals.get ('sjcl.password')Separately, I mention this:
Public.handleInit = function(conversation) {
conversation.addMediaTypeByName('application/json')
}
Here we indicate the type of response our backend
And in the functions
Public.handlePost or
Public.handleGet we create answers for Post or Get requests.
You can start the application with the command:
sincerity start restlet
from the myprudence directory.
By default, the application will start on port 8080 (http: // localhost: 8080 /). Port and virtual host can be changed in the configuration files of the framework.
Windows
Since the framework is multiplatform, it is logical that it can work not only on nix. For linux, you can download the deb or rpm sincerity package and install it on the system. For windows, I would recommend downloading the zip archive and running the sincerity.bat file. After the container has been created, all the files from the archive must be copied to the container folder and later started with the
sincerity.bat start restler
from there.
That remarkable in prudence, than it differs from node.js - it is written on the
site . There is also documentation, code samples and API links.