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
cookies
cookies
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.
session
cookies
Session data stored in encrypted user cookie.
Application state stored in a long running process.
template
template
websocket
websocket
Websockets.
Macros
Macro for defining a router in submillisecond.
The static router can be used to serve static files within a folder.
Structs
An application containing a router for listening and handling incoming
requests.
The request body.
Errors that can happen when using submillisecond.
Marker type for functions that satisfy
ProcessSafeHandler
.Json
json
Json can be used as an extractor, or response type.
Marker type for objects that satisfy
ProcessSafeHandler
.Wrapper for
http::Request
containing params and cursor.Extractor and response that works with typed header values from
headers
.Traits
A handler is implemented for any function which takes any number of
extractors, and returns any type that implements
IntoResponse
.Implemented for process-safe
Handlers
.Type Definitions
Alias for a type-erased error type.
Derive Macros
The
NamedParam
derive macro can be used to implement FromRequest
for a
struct.