summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2023-11-14 17:14:33 +0200
committerLars Wirzenius <liw@liw.fi>2023-11-14 17:14:33 +0200
commit8b8a935ff1103497ac9b37058d5a472fe0f1878b (patch)
tree95a8ffc101e6004519fc5fa045f2b62dd2e9a5a9
parentbfc5384ad217ca00bda610f6e57949e367a58e95 (diff)
downloadnative-ci-simulation-8b8a935ff1103497ac9b37058d5a472fe0f1878b.tar.gz
hmm
Signed-off-by: Lars Wirzenius <liw@liw.fi>
-rw-r--r--Cargo.toml3
-rw-r--r--rustfmt.toml1
-rw-r--r--src/main.rs37
3 files changed, 39 insertions, 2 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 62308ae..3c9543f 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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(),
+ }),
+ )
}