Switching to axum and askama
This commit is contained in:
parent
917bb24fc4
commit
9a44a77120
4 changed files with 505 additions and 659 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
target/
|
||||||
1100
Cargo.lock
generated
1100
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -6,5 +6,10 @@ edition = "2021"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-web = "4"
|
askama = "0.12.1"
|
||||||
actix-htmx = "0.3"
|
axum = "0.7.2"
|
||||||
|
tokio = { version = "1.35.0", features = ["full"] }
|
||||||
|
tower = "0.4.13"
|
||||||
|
tower-http = { version = "0.5.0", features = ["fs"] }
|
||||||
|
tracing = "0.1.40"
|
||||||
|
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
|
||||||
|
|
|
||||||
54
src/main.rs
54
src/main.rs
|
|
@ -1,43 +1,15 @@
|
||||||
use actix_htmx::{Htmx, HtmxMiddleware, TriggerType};
|
use tracing::info;
|
||||||
use actix_web::{web, App, HttpResponse, HttpServer, Responder};
|
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
|
||||||
|
|
||||||
#[actix_web::main]
|
#[tokio::main]
|
||||||
async fn main() -> std::io::Result<()> {
|
async fn main() {
|
||||||
HttpServer::new(|| {
|
tracing_subscriber::registry()
|
||||||
App::new()
|
.with(
|
||||||
.wrap(HtmxMiddleware)
|
tracing_subscriber::EnvFilter::try_from_default_env()
|
||||||
.service(web::resource("/contact/1/edit").to(index))
|
.unwrap_or_else(|_| "with_axum_htmx_askama=debug".into()),
|
||||||
})
|
)
|
||||||
.bind("0.0.0.0:8080")?
|
.with(tracing_subscriber::fmt::layer())
|
||||||
.run()
|
.init();
|
||||||
.await
|
|
||||||
}
|
info!("hello, web server!");
|
||||||
|
|
||||||
async fn index(htmx: Htmx) -> impl Responder {
|
|
||||||
let mut body: &str = "did not work";
|
|
||||||
if htmx.is_htmx {
|
|
||||||
body = r#"<form hx-put="/contact/1" hx-target="this" hx-swap="outerHTML">
|
|
||||||
<div>
|
|
||||||
<label>First Name</label>
|
|
||||||
<input type="text" name="firstName" value="Joe">
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label>Last Name</label>
|
|
||||||
<input type="text" name="lastName" value="Blow">
|
|
||||||
</div>
|
|
||||||
<div class="form-group">
|
|
||||||
<label>Email Address</label>
|
|
||||||
<input type="email" name="email" value="joe@blow.com">
|
|
||||||
</div>
|
|
||||||
<button class="btn">Submit</button>
|
|
||||||
<button class="btn" hx-get="/contact/1">Cancel</button>
|
|
||||||
</form>"#
|
|
||||||
}
|
|
||||||
htmx.trigger_event(
|
|
||||||
"my_event".to_string(),
|
|
||||||
Some(r#"{"level": "info", "message": "my event message!"}"#.to_string()),
|
|
||||||
Some(TriggerType::Standard)
|
|
||||||
);
|
|
||||||
|
|
||||||
HttpResponse::Ok().content_type("text/html").body(body)
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue