diff options
author | Lars Wirzenius <liw@liw.fi> | 2023-11-14 17:14:33 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2023-11-14 17:14:33 +0200 |
commit | 8b8a935ff1103497ac9b37058d5a472fe0f1878b (patch) | |
tree | 95a8ffc101e6004519fc5fa045f2b62dd2e9a5a9 | |
parent | bfc5384ad217ca00bda610f6e57949e367a58e95 (diff) | |
download | native-ci-simulation-8b8a935ff1103497ac9b37058d5a472fe0f1878b.tar.gz |
hmm
Signed-off-by: Lars Wirzenius <liw@liw.fi>
-rw-r--r-- | Cargo.toml | 3 | ||||
-rw-r--r-- | rustfmt.toml | 1 | ||||
-rw-r--r-- | src/main.rs | 37 |
3 files changed, 39 insertions, 2 deletions
@@ -6,3 +6,6 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +axum = "0.6.20" +serde = { version = "1.0.192", features = ["derive"] } +tokio = { version = "1.34.0", features = ["macros", "rt-multi-thread"] } diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..3a26366 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1 @@ +edition = "2021" diff --git a/src/main.rs b/src/main.rs index e7a11a9..72abefc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,36 @@ -fn main() { - println!("Hello, world!"); +use axum::{ + http::StatusCode, + response::IntoResponse, + routing::{get, post}, + Json, Router, +}; +use serde::Serialize; + +#[tokio::main] +async fn main() { + let app = Router::new() + .route("/", get(go_away)) + .route("/runs", post(create_run)); + axum::Server::bind(&"127.0.0.1:8000".parse().unwrap()) + .serve(app.into_make_service()) + .await + .unwrap(); +} + +async fn go_away() -> (StatusCode, impl IntoResponse) { + (StatusCode::FORBIDDEN, ()) +} + +#[derive(Serialize)] +struct Run { + id: String, +} + +async fn create_run() -> (StatusCode, impl IntoResponse) { + ( + StatusCode::CREATED, + Json(Run { + id: "cafebeef".into(), + }), + ) } |