first prototype with builtin functions

This commit is contained in:
Jonas_Jones 2023-12-08 18:33:02 +01:00
parent 9b75ff869b
commit b852500513
3 changed files with 25 additions and 21 deletions

View file

@ -2,6 +2,7 @@ use std::env;
use warp::Filter;
use crate::v1::get_v1_routes;
use crate::{Logger, parse_ip};
@ -13,18 +14,11 @@ pub async fn serve() {
let socket_addr = parse_ip();
// GET /hello/warp => 200 OK with body "Hello, warp!"
let hello = warp::path!("hello" / String)
.map(|name| format!("Hello, {}!", name));
let root = warp::path::end()
.map(|| warp::reply::html("<h1>jonas_jones-api!</h1>\n<p>this is a placeholder (hopefully)</p>"));
let v1 = warp::path!("v1" / String)
.map(|name| format!("Hello, {}!", name));
// GET (any) => reply with return from handle_path
let routes = get_v1_routes()
.or(warp::any().map(|| warp::reply::with_status("Not Found", warp::http::StatusCode::NOT_FOUND)));
let routes = hello.or(v1).or(root);
warp::serve(routes)
.run(socket_addr)