Crates.io | velvet-web |
lib.rs | velvet-web |
version | 0.6.13 |
source | src |
created_at | 2024-06-06 06:41:52.060442 |
updated_at | 2024-10-11 17:46:56.259348 |
description | Wrapper stack for webapp apis |
homepage | https://github.com/raffaeleragni/velvet |
repository | https://github.com/raffaeleragni/velvet |
max_upload_size | |
id | 1263451 |
size | 167,626 |
(original repo: https://github.com/raffaeleragni/velvet)
A layer of republish and small functions to remove some boilerplate on web stacks.
For a reference/example of a project using it: https://github.com/raffaeleragni/veltes
Other sample projects that use velvet:
Axum
sqlx
(postgres,sqlite,mysql)Askama
(folder templates/)sentry
supportedprometheus
under /metrics/prometheus
The askama templates and the static RustEmbed will be compiled in and not required at runtime.
The sqlx migrations are not embedded, and will be needed at runtime.
Proc macros cannot be transferred transitively, so crates need to be added again at project root in order to access them. For example tokio
or serde
.
use velvet_web::prelude::*;
#[tokio::main]
async fn main() {
App::new().route("/", get(index)).start().await.unwrap();
}
async fn index() -> impl IntoResponse {
"Hello World"
}
Default log level is error
. To change the level use the env var RUST_LOG=info|debug|warn
.
To get structured logging (json
logs) pass env var STRUCTURED_LOGGING=true
.
Metrics available at /metrics/prometheus
.
The custom metrics will be visible as soon as the first use happens, but only when used after App startup, not before.
For example, all the routes will work when used like this.
Adding a .env
file with DATABASE_URL=sqlite::memory:
, and enabling the feature sqlite
in crate velvet_web
.
Adding a .env
file with JWT_SECRET=secret
and enabling the feature auth
in velvet_web
.
JWK urls are also supported with a different enum initialization JWT::JWK.setup().await?
.
Need to include crate rust_embed
as this uses proc macros.
Using also Askama templates, and JWT through cookie setting.
Mail setup works only with TLS (port 465 if not set)