Crate submillisecond

source ·
Expand description

Submillisecond is a lunatic web framework.

Usage

First, add submillisecond as a dependency in Cargo.toml:

[dependencies]
submillisecond = "0.1"

Then, add a .cargo/config.toml to configure the target and runner:

[build]
target = "wasm32-wasi"

[target.wasm32-wasi]
runner = "lunatic"

Finally, define a handler and router, and run your application:

use submillisecond::{router, Application};

fn index() -> &'static str {
    "Hello from Submillisecond!"
}

fn main() -> std::io::Result<()> {
    Application::new(router! {
        GET "/" => index
    })
    .serve("0.0.0.0:3000")
}

The submillisecond repository has some more examples to help you get started.

High-level features

Submillisecond has some notable features including:

  • Router macro for performant router generated at compile-time.
  • Handlers: functions taking any number of extractors and returning any type that implements IntoResponse.
  • Extractors: types that parse the request to provide useful data.
  • Middleware: any handler which calls req.next_handler().
  • Guards: types that protect routes per request.

Re-exports

Modules

  • cookiescookies
    Cookies layer and extractor.
  • Default responses for errors.
  • Types and traits for extracting data from requests.
  • Params are data from the request url.
  • Uri reader using a cursor.
  • Types and traits for http responses.
  • sessioncookies
    Session data stored in encrypted user cookie.
  • Application state stored in a long running process.
  • templatetemplate
  • websocketwebsocket
    Websockets.

Macros

Structs

Traits

Type Definitions

  • Alias for a type-erased error type.
  • Signature of router function generated by the router! macro.

Derive Macros

  • The NamedParam derive macro can be used to implement FromRequest for a struct.