YES
This commit is contained in:
14
.gitignore
vendored
Normal file
14
.gitignore
vendored
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
# Generated by Cargo
|
||||||
|
# will have compiled files and executables
|
||||||
|
debug/
|
||||||
|
target/
|
||||||
|
|
||||||
|
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
|
||||||
|
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
|
||||||
|
Cargo.lock
|
||||||
|
|
||||||
|
# These are backup files generated by rustfmt
|
||||||
|
**/*.rs.bk
|
||||||
|
|
||||||
|
# MSVC Windows builds of rustc generate these, which store debugging information
|
||||||
|
*.pdb
|
||||||
12
Cargo.toml
Normal file
12
Cargo.toml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
[package]
|
||||||
|
name = "java-ws-sucks"
|
||||||
|
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.3.1"
|
||||||
|
serde = {version = "1.0.163", features = ["derive"]}
|
||||||
|
serde_json = "1.0.96"
|
||||||
|
serde_urlencoded = "0.7.1"
|
||||||
49
src/main.rs
Normal file
49
src/main.rs
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
use actix_web::{get, post, web, App, HttpResponse, HttpServer, Responder};
|
||||||
|
|
||||||
|
use serde::Deserialize;
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
pub struct Calc {
|
||||||
|
num1: i32,
|
||||||
|
num2: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[get("/add")]
|
||||||
|
async fn add(calc: web::Query<Calc>) -> String {
|
||||||
|
let number = calc.num1 + calc.num2;
|
||||||
|
number.to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[get("/sub")]
|
||||||
|
async fn sub(calc: web::Query<Calc>) -> String {
|
||||||
|
let number = calc.num1 - calc.num2;
|
||||||
|
number.to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[get("/mult")]
|
||||||
|
async fn mult(calc: web::Query<Calc>) -> String {
|
||||||
|
let number = calc.num1 * calc.num2;
|
||||||
|
number.to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[get("/div")]
|
||||||
|
async fn div(calc: web::Query<Calc>) -> String {
|
||||||
|
if calc.num2 == 0 {
|
||||||
|
return format!("CANNOT DIVIDE BY 0!!!!!");
|
||||||
|
}
|
||||||
|
let number = calc.num1 / calc.num2;
|
||||||
|
number.to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[actix_web::main]
|
||||||
|
async fn main() -> std::io::Result<()> {
|
||||||
|
HttpServer::new(|| {
|
||||||
|
App::new()
|
||||||
|
.service(add)
|
||||||
|
.service(sub)
|
||||||
|
.service(mult)
|
||||||
|
.service(div)
|
||||||
|
})
|
||||||
|
.bind(("127.0.0.1", 8080))?
|
||||||
|
.run()
|
||||||
|
.await
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user