Started implementing Axum

This commit is contained in:
Martin Berg Alstad
2024-06-05 22:09:12 +02:00
parent 096e2105dd
commit c4393e94bf
8 changed files with 835 additions and 2 deletions

2
src/routing/mod.rs Normal file
View File

@ -0,0 +1,2 @@
pub(crate) mod simplify;
pub(crate) mod table;

37
src/routing/simplify.rs Normal file
View File

@ -0,0 +1,37 @@
use axum::{Router, routing::get};
use axum::extract::{Path, Query};
use serde::Deserialize;
use crate::language::{AcceptLanguage, Language};
pub fn router() -> Router<()> {
Router::new()
.nest("/simplify",
Router::new()
.route("/:exp", get(simplify))
.route("/table/:exp", get(simplify_and_table)),
)
}
const fn default_true() -> bool {
true
}
#[derive(Deserialize, Debug)]
struct QueryOptions {
#[serde(default)]
lang: Language,
#[serde(default = "default_true")]
simplify: bool,
#[serde(default)]
case_sensitive: bool,
}
// TODO
async fn simplify(Path(path): Path<String>, query: Query<QueryOptions>, accept_language: Option<AcceptLanguage>) -> String {
format!("Path: {}, Query: {:?}, Accept-language header: {:?}", path, query, accept_language)
}
async fn simplify_and_table() {
unimplemented!("Not yet implemented")
}

13
src/routing/table.rs Normal file
View File

@ -0,0 +1,13 @@
use axum::Router;
use axum::routing::post;
pub fn router() -> Router<()> {
Router::new()
.nest("/table", Router::new()
.route("/", post(table)),
)
}
async fn table() {
unimplemented!("Not yet implemented")
}