mirror of
https://github.com/JonasunderscoreJones/jonas_jones-api.git
synced 2025-10-23 09:09:18 +02:00
first prototype with builtin functions
This commit is contained in:
parent
9b75ff869b
commit
b852500513
3 changed files with 25 additions and 21 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue