← Choosing a web framework

Runique vs Cot

Contents

CLI

CommandCotRunique
Installcargo install --locked cot-clicargo install runique --features sqlite --locked
Create a projectcot new namerunique new name
Migrations (generate)cot migration makerunique makemigrations
Empty migrationcot migration new <name>—
Migrations (apply)automatic at startuprunique migration up
Migrations (roll back)cargo run migration rollback <name>runique migration down -n 1
Migration statuscot migration listrunique migration status
Create a superusercode in App::init in the guide's examplerunique create-superuser
Collect static filescargo run -- collect-static public/—
Startcargo runcargo run
Code reloadbacon (generated bacon.toml)—

Routing

FeatureCotRunique
Route declarationRouter::with_urls([Route::with_handler_and_name("/", index, "index")])url.rs with the urlpatterns!{} macro
Dynamic routes"/hello/{name}""/users/{id}" in urlpatterns!
Reverse URLcot::reverse!(urls, "name"){% link "view_name" %}
Path parameterPath(name): Path<String> extractorAxum Path or request.get_path_as::<i32>("id")

Views / Handlers

FeatureCotRunique
Handlerasync fn index() -> cot::Result<Html>async fn my_view(mut request: Request) -> AppResult<Response>
Database accessdb: Database extractorrequest.engine.db
Template renderingIndexTemplate { .. }.render()?request.render("template.html")
Redirectreverse_redirect!(request, "name")Redirect::to("/url")
Flash messages—success!, error!, info!, warning! macros
Error pageserror_handler(), debug page with debug = true404.html, 500.html templates, debug page with DEBUG=true
APIopenapi, swagger-ui features—

Forms

FeatureCotRunique
Definition#[derive(Form)]#[form(schema = blog, fields = [...])] or a manual RuniqueForm
Reading and validationContactForm::from_request(&mut request).await?ValidationForm::try_form(form, &request).await
Built-in validation#[form(opts(max_length = 100))]model or field constraints
Custom validationcontext.add_error(FormErrorTarget::Field("title"), ...)async clean(), with database access
HTML rendering{{ form }} or form.fields(){% form.form_name %} or {% form.form_name.field %}
Built-in CSRF—automatic, injected before the first field
Filesform/fields/files.rsFileField and MediaField: type, size, content signature for images, audio and video

Templates

FeatureCotRunique
EngineAskama, templates bound to a structTera
Inheritance{% extends %} / {% block %}same
Inclusion{% include %}same
Static filesstatic_files!(...), StaticFiles extractor{% static "file" %}, with SRI in production
Static file versioningrewrite = "query_param"automatic ?v=
Reverse URLcot::reverse!(urls, "name"){% link "name" %}
Internationalization—t() and tf() in Rust, 9 languages for the framework's texts

ORM / Database

FeatureCotRunique
ORMits own ORM (sea-query, sqlx)SeaORM
EnginesSQLite, PostgreSQL, MySQL, all on by defaultSQLite, PostgreSQL, MySQL, one engine per build
Model definition#[model] on a structmodel!{} macro
Foreign keyForeignKey<User>belongs_to, with a required on-delete action
Queriesquery!(Customer, $id == 5), Customer::objects()search!, Model::objects
Bulk insertbulk_insertSeaORM
Transactionsdb.begin(), nesting through savepointsrequest.db_atomic() and SeaORM
Custom migration#[migration_op], forwards and backwardshand-written SeaORM migration

Authentication

FeatureCotRunique
Login / LogoutAuth extractor: auth.login(...), auth.logout()authenticate_user() + login(), logout()
UsersDatabaseUser, DatabaseUserAppeihwaz_users table, extensible through extend!{}
Sessionsmemory, database, file, Redis storestower-sessions (memory + database fallback), custom store possible
Session cookieSecure, HttpOnly, SameSite=Strict by default, configurableHttpOnly, SameSite=Strict, Secure in production
Password hashingArgon2Argon2 by default
Brute-force protection—LoginGuard
Password reset—tokens hashed in the database, single-use, with an expiry

Security

FeatureCotRunique
CSRF—always on
CSP and security headers—on by default, nonce per request
Rate limiting—RateLimiter, declared per route
CORS—.with_cors(...)
Allowed hosts—.with_allowed_hosts(...)
Open redirect—middleware always on

Admin panel

FeatureCotRunique
Setup#[derive(AdminModel)] + DefaultAdminModelManagertyped ModelAdmin builder + AdminSite.register(...)
Full CRUDbuilt inbuilt in
Paginationbuilt in.page_size(n), .per_page(n)
Search / filters—.search([...]), .filter([...])
Bulk actions—.action(Col, value, "Label")
Accesssigned-in userranks, admins' permissions per account (table and column)
History—built in

Email and cache

FeatureCotRunique
Sending emailEmailMessage::builder(), email featureEmail::new().send()
Dev backend (console)type = "console"EMAIL_BACKEND=console
Configuration[email] in TOML.env
Cachememory, Redis, file (Cache)—

Observability / Logging

FeatureCotRunique
Foundationtracingtracing
Configuration—RuniqueLog tree, per domain, stdout, file, LogSink

Tests

FeatureCotRunique
Commandcargo testrunique test
UnitTestRequestBuildertower::ServiceExt::oneshot
IntegrationClient::new(MyProject)reqwest
Test databaseTestDatabase::new_sqlite(), new_postgres, new_mysqlrunique_test, one transaction per test
End to end#[cot::e2e_test]—

Deployment

AspectCotRunique
Configurationconfig/dev.toml, config/prod.toml.env, RUNIQUE_ENV
Automatic TLS—acme feature
LicenseMIT or Apache-2.0MIT

What's coming in Runique