webapi, inital schema and routes (get_users)

provides the infrastructure for the webapi including setting up the
server and the routes.

Implements get_users as a test route
This commit is contained in:
Julia Lange 2026-03-03 10:45:36 -08:00
parent 1400b2fc95
commit 92763fd7dc
Signed by: Julia
SSH key fingerprint: SHA256:5DJcfxa5/fKCYn57dcabJa2vN2e6eT0pBerYi5SUbto
7 changed files with 197 additions and 0 deletions

View file

@ -0,0 +1,35 @@
use serde::Serialize;
use serde_json::json;
use axum::{Json, Router, response::IntoResponse, routing::get};
use reqwest::StatusCode;
mod get_users;
use crate::AppState;
pub type ApiResult<T> = Result<ApiResponse<T>, ApiError>;
pub struct ApiResponse<T>(pub StatusCode, pub T);
pub struct ApiError {
pub status: StatusCode,
pub error: &'static str,
pub message: String,
}
pub fn router() -> Router<AppState> {
Router::new()
.route("/get_users", get(get_users::handler))
}
impl IntoResponse for ApiError {
fn into_response(self) -> axum::response::Response {
let body = json!({ "error": self.error, "message": self.message });
(self.status, Json(body)).into_response()
}
}
impl<T: Serialize> IntoResponse for ApiResponse<T> {
fn into_response(self) -> axum::response::Response {
(self.0, Json(self.1)).into_response()
}
}