SnamlService is platform for microservice applications. SnamlScript is a language to develop MicroService and Web applications. It is available in Github as an Open Source software with MIT License. SanmlScript can work along with various Web frameworks like jQuery, Bootstrap, Material Design and D3JS.
HTML (HyperText Markup Language) is a description language for web document. Berent. Lee innovated the HTML from SGML. Netscape first implemented a widely used HTML browser. Later HTML5 becomes a defacto standard for web documents and applications while the Extensible Markup Language (XML) of W3 standard extended HTML to allow authors define new tags and attributes. HTML5 is designed to be the presentation standard for both web and mobile documents. Like other description languages, HTML5 is suitable to represent embedded documents. However, since HTML5 language is lack of variables, it is hard to use HTML5 as a programming language. Therefore, HTML5 document may be not applied well on modularity and reusability. To do programming, HTML5 must work with JavaScript language.
Tcl is a Tool Command Language innovated by Dr. Jhon Ousterhout in the late 1980s. It is a typeless scripting language with simple and elegant syntax. It originated from unix shell command language. Because of its command, substitution and grouping syntax, Tcl is very powerful and flexible for string processing and glue components. However, because of the lack of block commands, Tcl is difficult to express embedded documents. After many years development lots of new features have been added into the Tcl 8.6 such as event, lambda, and coroutine.
SnamlScript adapted the syntax of Tcl. In addition, SnamlScritp added block command and inline command to integrate the Tcl with HTML5 for Web programming. SnamlScript code can generate a HTML5 document dynamically and make a web app more maintainable, modifiable, and reusable in high-level consistence. In addition, SnamlScript is much easier to connect to a database and present contents in a database.
Microservice is an app with a single function. It is language independent but usually requires a server to run a process with an API of function for service interaction. Then a Container can enclose a microservice to run on Cloud or IoT environment.
SnamlService is platform for microservice applications. By integration of a web server with SnamlScript, developers can easily develop in-memory Microservice for applications of Cloud and Internet of Things. The size of SnamlService can be as small as 2MB that is 5x smaller than some other microservices.
use SnamlScript package and render to a html file.
package require SnamlScript _output file hello.htmloutput string by quote command inside head.
_html lang='en' _head _title; quote "Hello SnamlScript"; title_ head_
display a phrase inside body.
_body quote "Welcome to SnamlScript!" body_ html_
close output
output_
The example of simplest server demonstrates a http server to response hello. In advanced Microservice we applied Fiber (Coroutine) for high performance and fast response and avoiding the spaghetti problem in async server.
package require SnamlScript
response from server
proc createServer {channel addr port} { set chan $channel quote "HTTP/1.1 200 OK\nContent-Type: text/html\n\n" quote "Hello World!" close $chan }
visit server at http://localhost:7788
set soc [socket -server createServer 7788] vwait forever
To run Angular 2 in SnamlService, we got powerful support of JavaScript framework.
proc app.template.html {} { _template _h1; quote "First Angular 2 App."; h1_ template_ return [template] }
Mapping to 4 parts of Angular 2, main is the entry point; render.sml is the SnamlScript for HTML code; main.ts is the TypeScript entry point; app.component.ts is the component definition by TypeScript; app.template.html is the content of HTML5.
proc app.component.ts {} { return " import {Component} from 'angular2/core'; @Component({ selector: 'my-app', template: '[app.template.html]' }) export class AppComponent { } " }
main function defines AppComponent and bootstrap.
proc main.ts {} { return { import {bootstrap} from 'angular2/platform/browser' import {AppComponent} from './app.component' bootstrap(AppComponent); } }
render.sml will render SnamlScript into HTML5.
proc render.sml {} { __doctype html _html _head _title; quote {Angular 2 Example}; title_ __meta name='viewport' content='width=device-width, initial-scale=1'
load angular 2 beta and typescript from CDN network. Load libraries while IE required polyfills in this exact order
set cdnjslib "https://cdnjs.cloudflare.com/ajax/libs" _script src="$cdnjslib/es6-shim/0.33.3/es6-shim.min.js"; script_ _script src="$cdnjslib/systemjs/0.19.16/system-polyfills.js"; script_ set angularjs "https://code.angularjs.org" _script src="$angularjs/2.0.0-beta.3/angular2-polyfills.js"; script_ _script src="$angularjs/tools/system.js"; script_ _script src="$angularjs/tools/typescript.js"; script_ _script src="$angularjs/2.0.0-beta.3/Rx.js"; script_ _script src="$angularjs/2.0.0-beta.3/angular2.dev.js"; script_
configure SystemJS.
_script quote { System.config({ transpiler: 'typescript', typescriptOptions: { emitDecoratorMetadata: true }, packages: {'app': {defaultExtension: 'ts'}} }); System.import('app/main').then(null, console.error.bind(console)); } script_ head_
load and display application.
_body quote {Loading... } body_ html_ }
main entry as http or https.
main http