No description
Find a file
2024-12-24 15:49:11 +01:00
.woodpecker nightly 2024-12-18 19:58:33 +01:00
examples update 2024-12-24 02:12:16 +01:00
src htmx feature 2024-12-24 15:49:11 +01:00
.gitignore update + htmx 2024-12-22 18:37:45 +01:00
build.rs update + htmx 2024-12-22 18:37:45 +01:00
Cargo.lock update 2024-12-24 02:12:16 +01:00
Cargo.toml htmx feature 2024-12-24 15:49:11 +01:00
README.md update + htmx 2024-12-22 18:37:45 +01:00

Based

Based is a micro framework providing web dev primitives.

Features

  • User Auth
  • PostgresDB Connection
  • Logging
  • Request Contexts
  • Templates (Shell)

User Auth

To use the user auth feature, make sure a migration has added the following to your PostgresDB:

CREATE TYPE user_role AS ENUM ('regular', 'admin');

CREATE TABLE IF NOT EXISTS users (
    username VARCHAR(255) NOT NULL PRIMARY KEY,
    "password" text NOT NULL,
    user_role user_role NOT NULL DEFAULT 'regular'
);

CREATE TABLE IF NOT EXISTS user_session (
    id UUID NOT NULL PRIMARY KEY DEFAULT gen_random_uuid(),
    token text NOT NULL,
    "user" varchar(255) NOT NULL,
    FOREIGN KEY("user") REFERENCES users(username)
);

HTMX

Based has a route for serving HTMX at based::htmx::htmx_script_route which you can include in your rocket routes!. The HTMX script will be available at /assets/htmx.min.js.

Additionally you can check if a requests originates from HTMX:

#[get("/")]
pub async fn index(ctx: RequestContext) -> StringRespopnse {
    if ctx.is_htmx {
        ...
    } else {
        ...
    }
}