api-server/src/main.rs

41 lines
969 B
Rust
Raw Normal View History

mod dem;
use std::io::{self, BufRead};
use crate::dem::elevation_from_coordinates;
use axum_macros::debug_handler;
use axum::{
extract::Path, http::StatusCode, routing::{get, post}, Json, Router,
};
#[tokio::main]
async fn main() {
// initialize tracing
tracing_subscriber::fmt::init();
// build our application with a route
let app = Router::new()
// `GET /` goes to `root`
.route("/", get(root))
.route("/elevation/:lat/:lon", get(get_elevation));
// run our app with hyper, listening globally on port 3000
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
axum::serve(listener, app).await.unwrap();
}
// basic handler that responds with a static string
async fn root() -> &'static str {
"Hello, World!"
}
#[debug_handler]
async fn get_elevation(Path((lat, lon)): Path<(f64, f64)>) -> String{
let ele = elevation_from_coordinates(lat, lon);
format!("{ele}")
}