easy-sms-rust/src/main.rs
2023-01-14 21:19:32 +08:00

31 lines
728 B
Rust

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