Welcome to Rocal
What's Rocal?
Rocal is Full-Stack WASM framework that can be used to build fast and robust web apps thanks to high performance of WebAssembly and Rust's typing system and smart memory management.
Rocal adopts MVC(Model-View-Controller) architecture, so if you are not familiarized with the architecture, we highly recommend learning the architecture first before using Rocal. That's the essential part to make your application with Rocal effectively.
Getting Started
// ... in HelloWorldController
// ... in HelloWorldView
// ... in HelloWorldTemplate
As you can see the quick example, to render HTML with MVC architecture, in this case, the router and each controller, view, and template can be written like that.
Requirements
- Install Rocal by the command below if you haven't yet:
On MacOS or Linux
|
On Windows
- wasm-pack which is used to build an Rocal application
- brotli to be used compressing releasing files to publish.
- Create a new Rocal application:
where myapp
is the application name
- Run to access the application:
Go to http://127.0.0.1:3000
and you'll see the welcome message!
- Build the application without running it:
- See the generated directories and files:
Probably, you could find some directories and files in the application directory after executing the leading commands.
Especially, if you want to learn how the application works, you should take a look at lib.rs, controllers, views, and models.
Some Rocal macros are used to build the application such as config!
and #[rocal::main]
which are in src/lib.rs
and required to run. On top of that, you could see route!
macro that provides you with an easy way to set up application routing.
Other than the macros, there is an essential struct to communicate with an embedded database which is now we utilize SQLite WASM.
You could write like below to execute queries to the database.
use Deserialize;
let database = crateCONFIG.get_database.clone;
let result: = database.query.await;
database.exec.await;
And, to create tables, you are able to put SQL files in db/migrations
directory.
e.g. db/migrations/202502090330_create_user_table.sql
integer primary key,
first_name text not null,
last_name text not null,
created_at datetime default current_timestamp
);
(
id
- (Optional) Publish a Rocal application:
where myapp
is the application name
Then you can find release/
and release.tar.gz
to publish to your hosting server.
License
Rocal is released under the MIT License.