easy-sms-rust/src/main.rs

31 lines
728 B
Rust
Raw Normal View History

2023-01-14 10:04:15 +00:00
#[macro_use] extern crate rocket;
2023-01-14 13:19:32 +00:00
use std::net::Ipv4Addr;
use rocket::Config;
2023-01-14 10:04:15 +00:00
use rocket::serde::json::Json;
use easy_sms::telecom;
2023-01-14 13:19:32 +00:00
use easy_sms::telecom::Message;
2023-01-14 10:04:15 +00:00
#[get("/")]
async fn index() -> &'static str {
"Hello, world!"
}
#[post("/send_msg", format="application/json", data="<message>")]
async fn send_msg(message: Json<Message<'_>>) -> String {
2023-01-14 13:19:32 +00:00
let body = telecom::send_msg(message.into_inner()).await.expect("Error");
2023-01-14 10:04:15 +00:00
format!("{}", &body)
}
#[launch]
fn rocket() -> _ {
2023-01-14 13:19:32 +00:00
let config = Config {
port: 80,
address: Ipv4Addr::new(0,0,0,0).into(),
..Config::default()
};
rocket::custom(&config)
2023-01-14 10:04:15 +00:00
.mount("/", routes![index])
.mount("/", routes![send_msg])
}