This commit is contained in:
Johannes Heuel
2022-09-14 09:15:10 +02:00
commit 32f92b9320
5 changed files with 1209 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/target

1152
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

11
Cargo.toml Normal file
View File

@@ -0,0 +1,11 @@
[package]
name = "zoidberg"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
actix-web = "4"
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }

3
src/bin/hello.rs Normal file
View File

@@ -0,0 +1,3 @@
fn main() {
println!("hello");
}

42
src/main.rs Normal file
View File

@@ -0,0 +1,42 @@
use actix_web::{get, post, web, App, HttpResponse, HttpServer, Responder, Result};
use serde::Deserialize;
#[derive(Deserialize)]
struct Update {
id: i64,
status: String,
}
#[get("/register")]
async fn register() -> impl Responder {
HttpResponse::Ok().body("Worker node registered")
}
#[get("/fetch")]
async fn fetch() -> impl Responder {
HttpResponse::Ok().body("Here is some work")
}
#[post("/update")]
async fn update(u: web::Json<Update>) -> Result<String> {
Ok(format!("Job {} updated with status {}", u.id, u.status))
}
#[get("/")]
async fn index() -> impl Responder {
HttpResponse::Ok().body("Hello world!")
}
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| {
App::new()
.service(register)
.service(fetch)
.service(update)
.service(index)
})
.bind(("127.0.0.1", 8080))?
.run()
.await
}