Use get request parameters instead of routes

Signed-off-by: baalajimaestro <me@baalajimaestro.me>
This commit is contained in:
baalajimaestro 2022-11-20 09:09:56 +05:30
parent 028ca37763
commit 215753bb59
Signed by: baalajimaestro
GPG key ID: F93C394FE9BBAFD5
3 changed files with 26 additions and 4 deletions

15
Cargo.lock generated
View file

@ -7,6 +7,7 @@ name = "actix-backend"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"actix-web", "actix-web",
"serde",
"tera", "tera",
] ]
@ -1165,6 +1166,20 @@ name = "serde"
version = "1.0.147" version = "1.0.147"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d193d69bae983fc11a79df82342761dfbf28a99fc8d203dca4c3c1b590948965" checksum = "d193d69bae983fc11a79df82342761dfbf28a99fc8d203dca4c3c1b590948965"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.147"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4f1d362ca8fc9c3e3a7484440752472d68a6caa98f1ab81d99b5dfe517cec852"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "serde_json" name = "serde_json"

View file

@ -8,3 +8,4 @@ edition = "2021"
[dependencies] [dependencies]
actix-web = "4" actix-web = "4"
tera = "1.17.1" tera = "1.17.1"
serde = { version = "1.0", features = ["derive"] }

View file

@ -1,16 +1,22 @@
use actix_web::{get, App, HttpResponse, HttpServer, Responder, web::{Data}}; use actix_web::{get, App, HttpResponse, HttpServer, Responder, web::{Data, Query}};
use tera::{Tera, Context}; use tera::{Tera, Context};
use serde::Deserialize;
struct Template { struct Template {
paste: Tera, paste: Tera,
} }
#[derive(Deserialize)]
struct Paste {
paste_id: String,
}
#[get("/{paste_id}")]
async fn paste_render(data: Data<Template>) -> impl Responder { #[get("/")]
async fn paste_render(data: Data<Template>, paste: Query<Paste>) -> impl Responder {
let my_data = data.get_ref(); let my_data = data.get_ref();
let mut context = Context::new(); let mut context = Context::new();
context.insert("paste_content", "owo"); context.insert("paste_content", &paste.paste_id);
let rendered = my_data.paste.render("paste.html", &context); let rendered = my_data.paste.render("paste.html", &context);
HttpResponse::Ok().body(rendered.unwrap()) HttpResponse::Ok().body(rendered.unwrap())
} }