A comprehensive demonstration of the Solilang MVC Framework with scoped middleware support.
- Rust and Cargo (latest stable)
- Node.js (v16 or higher)
- npm or yarn
# Install dependencies
npm install# Start development server with hot reload and automatic Tailwind CSS compilation
soli serve . --dev
# Or use the shell script
./dev.shVisit http://localhost:5011 for the app, and http://localhost:5011/docs for full documentation.
When running in dev mode (--dev), Soli automatically handles Tailwind CSS:
- On startup: Compiles Tailwind CSS automatically
- On view changes: Recompiles when you edit
.slvtemplate files - On source CSS changes: Recompiles when files in
app/assets/css/change
No need to run a separate Tailwind watcher - just use soli serve . --dev!
tailwind.config.jsin project rootpackage.jsonwith abuild:cssscript- Node.js and npm installed
For production, use without the --dev flag:
soli serve .mvc_app/
├── app/
│ ├── controllers/ # Route handlers
│ │ ├── home_controller.sl
│ │ ├── users_controller.sl
│ │ └── admin_controller.sl
│ ├── middleware/ # Middleware functions
│ │ ├── auth.sl # Authentication (scope_only)
│ │ ├── request_stamp.sl # request timestamp (global_only)
│ │ └── logging.sl # Request logging (global_only)
│ ├── models/ # Data models
│ └── views/ # Templates
│ ├── home/
│ └── layouts/
├── config/
│ └── routes.sl # Route definitions
├── public/ # Static files
│ └── docs.html # Framework documentation
└── README.md # This file
Apply middleware only to specific routes:
// Only /admin/* routes require authentication
middleware("authenticate", -> {
get("/admin", "admin#index");
get("/admin/users", "admin#users");
});
// Public routes - no auth needed
get("/", "home#index");| Type | Option | Behavior |
|---|---|---|
| Global-Only | // global_only: true |
Runs for ALL routes, cannot be scoped |
| Scope-Only | // scope_only: true |
Only runs when explicitly scoped |
| Regular | No option | Runs globally by default, can also be scoped |
Generate standard CRUD routes automatically:
resources("users", null);Creates: GET /users, POST /users, GET /users/:id, etc.
Group routes under a common prefix:
namespace("api", -> {
middleware("authenticate", -> {
get("/api/users", "users#index");
});
});Full documentation available at: http://localhost:5011/docs
- Getting Started - Installation and quick start guide
- Architecture - MVC pattern explanation
- Controllers - Defining route handlers
- Middleware - Request/response processing
- Views - Template rendering and layouts
- Routing - DSL helpers and patterns
- Resources - RESTful route generation
- Configuration - Middleware options
Configure middleware behavior using special comments:
// order: 20 // Execution order (lower runs first)
// global_only: true // Only runs globally, cannot be scoped
// scope_only: true // Only runs when explicitly scopedAvailable helpers in routes.sl:
| Helper | Description |
|---|---|
get(path, action) |
GET request |
post(path, action) |
POST request |
put(path, action) |
PUT request |
delete(path, action) |
DELETE request |
patch(path, action) |
PATCH request |
resources(name, block) |
RESTful resource routes |
namespace(name, block) |
Route grouping |
middleware(name, block) |
Scoped middleware |
// config/routes.sl
// Scoped authentication middleware
middleware("authenticate", -> {
get("/admin", "admin#index");
get("/admin/users", "admin#users");
});
// Public routes
get("/", "home#index");
get("/about", "home#about");
// RESTful resources
resources("users", null);Solilang provides a Rails-like E2E testing framework for testing your controllers with real HTTP requests:
describe("PostsController", fn() {
before_each(fn() {
as_guest();
});
test("creates post", fn() {
login("user@example.com", "password");
response = post("/posts", {
"title": "New Post",
"body": "Content"
});
assert_eq(res_status(response), 201);
data = res_json(response);
assert_eq(data["title"], "New Post");
});
});| Function | Description |
|---|---|
get(path) |
GET request |
post(path, data) |
POST with body |
put(path, data) |
PUT replacement |
patch(path, data) |
PATCH partial update |
delete(path) |
DELETE resource |
head(path), options(path) |
Other methods |
set_header(name, value) |
Custom headers |
set_authorization(token) |
Bearer token auth |
set_cookie(name, value) |
Session cookies |
| Function | Description |
|---|---|
res_status(response) |
HTTP status code |
res_body(response) |
Response body string |
res_json(response) |
Parsed JSON response |
res_header(response, name) |
Specific header |
res_redirect(response) |
Is redirect? |
res_ok(response) |
2xx status? |
res_client_error(response) |
4xx status? |
res_server_error(response) |
5xx status? |
| Function | Description |
|---|---|
as_guest(), as_user(id), as_admin() |
Set auth state |
login(email, password), logout() |
Session management |
signed_in(), signed_out() |
Auth check |
with_token(token) |
JWT authentication |
# Run E2E tests
soli test tests/builtins/controller_integration_spec.sl
# Run all tests
soli test tests/builtins
# With coverage
soli test tests/builtins --coverageDocumentation: See docs/testing-guide.md for comprehensive testing documentation.
curl http://localhost:5011/
curl http://localhost:5011/health
curl http://localhost:5011/docscurl http://localhost:5011/docs/introduction
curl http://localhost:5011/docs/installation
curl http://localhost:5011/docs/routing
curl http://localhost:5011/docs/controllers
curl http://localhost:5011/docs/middleware
curl http://localhost:5011/docs/viewsThe development server supports hot reload:
- Edit controllers → changes apply immediately
- Edit middleware → changes apply immediately
- Edit routes → routes are reloaded
- Edit templates → pages are refreshed + Tailwind CSS recompiles automatically
- Edit source CSS (
app/assets/css/) → Tailwind CSS recompiles automatically
No restart needed!
| Middleware | Type | Description |
|---|---|---|
cors |
global_only | Adds CORS headers to all responses |
logging |
global_only | Logs all HTTP requests |
authenticate |
scope_only | Requires API key authentication (ready to use in routes) |
- Create
app/controllers/name_controller.sl:
def index(req: Any) {
return {"status": 200, "body": "Hello!"};
}
def show(req: Any) {
id = req["params"]["id"];
return {"status": 200, "body": "User " + id};
}- Add routes in
config/routes.sl:
get("/users", "users#index");
get("/users/:id", "users#show");- The
authenticatemiddleware uses a demo API key (secret-key-123) - In production, use proper authentication (JWT, sessions, etc.)
- CORS is configured for development; configure properly for production
- Full Docs: http://localhost:5011/docs
- GitHub: https://github.com/solilang/solilang
- Examples: See
examples/mvc_app/
Built with ❤️ using Solilang