Progressive RESTful framework that makes application development simple again. Even if you are not familiar with Rust yet you might be interested because it's designed to be as beginner-friendly as possible. Tutorials are available in the blog which is also built with prest. Beware that its still alpha and can only be recommended for pet projects and training because many breaking changes are expected.

It ain't easy to compete with Laravel, Rails, Nextjs and many others, but I always wanted a framework which enables simplicity in common development needs and allows any customizations/optimizations without switching languages. Rust provides ways to build servers, clients, AIs, blockchains, OS kernels and whatever else you might need, while also being arguably the most reliable practical language. Thanks to a lot of amazing dependencies under the hood prest re-exports a comprehensive toolkit for development and provides a bunch of features on top of them for simplicity:

Easy start

Create a default rust project, add prest dependency, bulk use everything from it, invoke init! macro and add your app's logic. No massive boilerplates, no custom required CLI tools.

Cargo.toml

[dependencies]
prest = "0.4"

src/main.rs

use prest::*;
fn main() {
    init!();
    ...
}

This macro can take additional args, but in general it reads the env variables, initializes the runtime, logging, database and other prest subsystems.

Server

High-performance, concurrent, intuitively routed. Basically it's re-exports axum, so it includes powerful middleware api, simple extractors to get information handlers need from requests and flexible return types. But prest also enchances it with a bunch of additional utilities to get started quickly - just run your router and everything else will be configured automatically.

route("/", get("Hello world")).run()

For deserialization of incoming data there is a small utility extractor Vals<T> which extracts fields from the query in GET requests and expects json bodies for other methods, for example:

route("/send_data", post(|Vals(data): Vals<Data>| async {/* data will be of type Data */}))

Router is built by composing routes and other routers like this:

let router = route("/path", /* handler */)
    .route("/:path_param", /* handler */)
    .layer(/* middleware */)
    .nest(/* another router */);

For more details about routing, handlers and layers check out axum's docs. Under the hood it's powered by tokio stack for extreme speed and reliability. Also, if you need to access runtime directly prest exports RT static which you can use. Serialize and Deserialize macros (check out serde for details) are re-exported from prest as well.

State

While axum provides a way to manage shared state it's relatively verbose so prest provides a bit easier solution - state! macro:

state!(GLOBAL: String = { sync_function()? });
state!(GLOBAL: String = async { async_function().await? });

It works with both sync and async initialization code, and supports ? operator inside. Under the hood it's using standard LazyLock, anyhow-based return type to support ? (but beware that errors in state initialization will panic and stop the app), and tokio's runtime when execution of async code is needed. Variables themselves are statics which can be used anywhere in your codebase, just keep in mind that if you'll need mutable globals you'll have to use RwLock, Mutex or smth alike.

UI

html! macro for rust'y templating forked from maud, easy styling with built-in tailwind classes which are compiled into css inside html, simple client-server interactions with htmx and it's aliases, unlimited flexibility with hyperscript. Smooth UX without separate front-end stacks:

html!{ 
    nav $"w-full bg-gray-900 rounded-full" {
        input $"text-xs lg:text-md" 
            name="search" 
            post="/search" 
            into="#search-results"
            swap-inner {} 
    }
    ...
    div #search-results {"response will be here!"}
}

For more details about these tools I suggest checking out their docs, overall they are pretty simple and intuitive by themselves but powerful enough for the vast majority of apps. Default prest bundle includes tailwind's presets and patched htmx version which sends non-GET request payloads in json format to easily use with Vals and includes a few other tweaks for better compatability.

Database

Embedded DB that works without running separate services based on GlueSQL for compatibility with SQL and sled for high-performance storage. Prest enchances them with the Table macro to automatically derive schema based on usual rust structs, and some helper functions to easily interact with the underlying tables without worrying about SQL injections. Just add your structs into the init! macro to make sure tables for them are initialized:

#[derive(Table, Deserialize)]
struct Todo {
    id: Uuid,
    task: String,
    done: bool,
}
...
init!(tables Todo/*, OtherTable, ... */)
...
Todo::find_all()
Todo::find_by_task("Buy milk")
Todo::select()
    .filter(col("done").eq(true))
    .order_by("task")
    .values()
...
let todo = Todo {
    id: Uuid::now_v7(),
    task: "Buy bread".into(),
    done: false,
};
todo.save()
todo.update_task("Buy candies")
assert!(todo.check_task("Buy candies"))
todo.remove()

It's aimed to support all the basic types supported by GlueSQL, Option<>, Vec<>, as well as custom ones which can be serialized/deserialized. As of now Table also requires derived Deserialize trait to enable DB editor in the...

Admin panel

Monitors host system's resources, collects filtered stats for requests/responses with their timings, high-level info and detailed traces, provides read/write GUI to all initialized tables, tracks scheduled tasks, and provide controls over remote host in local builds. While blog intentionally exposes access to it for demo purposes (cog in the menu), by default it is protected by...

Auth

Session and user management using passwords and OAuth/openID protocols. Based on the built-in DB, openidconnect-rs, axum-login and password-auth. Persisted in the built-in DB, can be initiated by leading users to the predefined routes, and can retrieve current auth/user info using extractors:

html!{ 
    // for username/password flow
    form method="POST" action=(LOGIN_ROUTE) { ... }
    // for oauth flow
    a href=(GOOGLE_LOGIN_ROUTE) {"Login with Google"}
}
...
route("/authorized-only", get(|user: User| async {"Hello world"}));
route("/optional", get(|auth: Auth| async {"auth.user is Option<User>"}));

To enable it you'll need the auth feature of prest:

prest = { version = "0.4", features = ["auth"] }

If someone requests a route which requires authorization 401 Unauthorized error will be returned.

Schedule

There is also a rust-based cron alternative for background tasks based on tokio-schedule and enchanced with some utilities and integrations. They can be spawned as easy as:

// can return either `()` or `Result<(), E: Display>` to enable `?`
RT.every(5).minutes().spawn(|| async { do_smth().await })
RT.every(1).day().at(hour, minute, second).spawn(...) 

You can also give names to your scheduled tasks and prest will collect additional stats over their timings and execution results:

RT.every(3).hours().schedule("my regular task", || async { ... })
RT.every(2).days().at(hour, minute, second).schedule(...) 

Logs

Logging is powered by tracing ecosystem with trace!, debug!, info!, warn! and error! macros:

info!("My variable value is {}", x); // supports same formatting as `format!` macro

Prest initializes a subscriber which collects these records into several streams: high-level INFO+ level logs are written in html format to be observed in the main admin panel page (and the shell in debug builds), and traces of all levels are also written in a non-blocking fashion to files split by days in the json format, which can be also explored through special page in the admin panel. By default prest filters low-level logs of its dependencies to avoid spamming your feeds, and you can also add more filters in the init! macro:

// like in the `scraping` example
init!(tables Story; log filters: ("html5ever", INFO), ("selectors", INFO));

Build utils

There is also another prest crate prest-build. Unlike usual dependencies it goes into build deps section:

[build-dependencies]
prest-build = "0.3"

It includes a couple of optional features - sass and typescript which allow transpilation and bundling for typescript/js and sass/scss/css respectfully:

// paths relative to the build script
bundle_ts("path to main ts/js file");
bundle_sass("path to main sass/scss/css file");

And their compiled versions can be embedded with embed_build_output_as! macro:

embed_build_output_as!(BuiltAssets);
...
router.embed(BuiltAssets)

They can be requested with the same name as originals but ts/tsx and scss/sass extensions will be replaced with js and css accordingly.

Also, there is a similar and more flexible macro embed_as! which can be used with arbitrary folders and files, and this macro is designed to read files from the hard drive as needed in debug builds to avoid slowing down compilation, but in release builds it will embed their contents into the binary and you'll get single-file binary with your whole app in it for convenience and faster file access. These macros generate rust structures which provide access for files' contents and metadata. Here is a snippet from the blogs internals which embeds projects files to render on its pages:

embed_as!(ExamplesDocs from "../" only "*.md");
embed_as!(ExamplesCode from "../" except "*.md");

General syntax:

embed_as!(StructName from "path" only "path or wildcard"/*, "..."*/ except "path or wildcard"/*, ...*/)

Such structs can be embedded into the router like this: .embed(StructName).

Deployment

Prest supports 1 click build-upload-start deploy script based on docker for cross-platform compilation, and comes with automatically configured TLS based on LetsEncrypt. To make it work you'll need to have docker engine installed, specify the domain in the Cargo.toml and provide credentials:

[package.metadata]
domain = "prest.blog"
# add when starting app locally in the shell or in the .env file
SSH_ADDR=123.232.111.222
SSH_USER=root
SSH_PASSWORD=verystrongpassword

And just click the Deploy button in the local admin panel! You can also manage deployments there: stop the current one, start a previous one, or cleanup old builds.

Anyway, even with the fastest framework and server users will still have to face network delays and you may want to provide more native-app-like experience so...

PWA

Core prest-build function is to build some of your routes into a WASM-based Service Worker and compose a Progressive Web Application so that your users can install it and access these routes offline. To make it work you'll need to add wasm-bindgen dependency and prest-build build-dependency, separate host-only from shared host+client code and initialize shared routes in the SW, and add a lil build script:

[dependencies]
...
wasm-bindgen = "0.2"
#[wasm_bindgen(start)]
pub fn main() {
    shared_routes().handle_fetch_events()
}
use prest_build::*;
fn main() {
    build_pwa(PWAOptions::new()).unwrap();
}

To embed the compiled assets into the host you can use the same embed_build_output_as! macro. By default it will only run full PWA build in the --release mode to avoid slowing down usual development, but you can use PWA=debug env variable to enforce full builds. The general idea is to render some of the templates on the client-side to provide extremely fast responses while also supporting server-side renders as a fallback and indexing mechanism. And get it all with just a few lines of boilerplate code. If PWA experience is not enough for you there is another available option...

Native

Running host functionality with a webview for offline-first apps. Somewhat like Electron but with much smaller and faster binaries. Based on the same libraries as Tauri but for rust-first apps. To build for desktops just enable webview feature like this:

prest = { version = "0.4", features = ["webview"] }

This is quite different from server-first or PWA apps and require quite different architecture, especially around auth and similar components. For mobile platforms you'll need to do some work as of now, but hopefully this will be mostly automated as well.

Others

And the story doesn't end here. Prest host includes a graceful shutdown mechanism which awaits currently processing requests and in-progress scheduled tasks before exiting, Server Sent Events utils to easily stream data to the clients, a whole bunch of small utils like Vals extractor and ok() function which can wrap return values of handler closures to provide to allow using ? operator inside of them. If you think that prest is missing some feature which may be useful for you or for modern app development in general - please add an issue in the repo!

getting started

If you aren't familiar with rust yet I strongly recommend to check out The Rust Book - definitely the best guide with interactive examples available in dozens of languages! Also, I suggest skimming through the first three chapters of the async book to get an overall understanding how concurrency works in rust.

Prest tutorials are designed to start from basics and then add more and more features on top:

  1. Todo = basic full-stack todo app in just about 50 lines of code
  2. PWA = 1 + PWA capabilities and an offline view, ~80 LoC
  3. Auth = 2 + username+password and Google auth, ~110 LoC
  4. Sync = 3 + synchronization between clients, ~130 LoC

There are also todo examples with alternative databases - postgres through seaorm or diesel, sqlite through sqlx or turbosql, mongo, redis. Also, there is a couple of examples that showcase how one might use prest with uncommon for web development tech: web scraper, Large Language Model and Solana blockchain program.

To run locally you'll need the latest stable rust toolchain. I also recommend setting up the rust-analyzer for your favourite IDE right away. To build & start any example from the cloned prest repo use cargo run -p EXAMPLE-NAME. Or just copy the selected example's code from the tutorials into local files and cargo run it. Some examples require additional setup and credentials which are mentioned in their docs.

what's next

This is a hobby project and plans change on the fly, but there are things I'd likely work on or consider next:

Some ideas are more complex/crazy but interesting:

There are also longer term things which will be needed or nice to have before the stable release of prest:

v0.4.0
made by Egor Dezhic