Inital API - Heath Endpoint
This commit is contained in:
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
/target
|
||||||
|
|
||||||
|
.vscode/
|
||||||
|
.idea/
|
||||||
1104
Cargo.lock
generated
1104
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
14
Cargo.toml
Normal file
14
Cargo.toml
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
[package]
|
||||||
|
name = "message-hideyoshi_com"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
axum = "0.7.4"
|
||||||
|
tokio = { version = "1.0.0", features = ["rt", "rt-multi-thread", "macros"] }
|
||||||
|
uuid = "1.7.0"
|
||||||
|
serde = { version = "1.0.197", features = ["derive"] }
|
||||||
|
serde_with = "3.6.1"
|
||||||
|
chrono = { version = "0.4.34", features = ["serde"] }
|
||||||
@@ -1,12 +1,9 @@
|
|||||||
use axum::{
|
use axum::{
|
||||||
extract::{Path, Query, State},
|
|
||||||
http::StatusCode,
|
http::StatusCode,
|
||||||
response::IntoResponse,
|
response::IntoResponse,
|
||||||
Json,
|
Json,
|
||||||
};
|
};
|
||||||
use uuid::Uuid;
|
use crate::model::generic_response::{GenericResponse};
|
||||||
|
|
||||||
use crate::model::{GenericResponse};
|
|
||||||
|
|
||||||
pub async fn health_check() -> impl IntoResponse {
|
pub async fn health_check() -> impl IntoResponse {
|
||||||
const MESSAGE: &str = "Server is running";
|
const MESSAGE: &str = "Server is running";
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
use axum::{
|
||||||
|
http::StatusCode,
|
||||||
|
response::IntoResponse,
|
||||||
|
Json,
|
||||||
|
};
|
||||||
|
use crate::model::send_message::{SendMessage};
|
||||||
|
|
||||||
|
pub async fn send_message(Json(payload): Json<SendMessage>) -> impl IntoResponse {
|
||||||
|
(StatusCode::OK, Json(payload))
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
pub mod health;
|
||||||
|
pub mod message;
|
||||||
17
src/main.rs
Normal file
17
src/main.rs
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
mod route;
|
||||||
|
mod model;
|
||||||
|
mod handler;
|
||||||
|
|
||||||
|
use axum::http::{
|
||||||
|
header::{ACCEPT, AUTHORIZATION, CONTENT_TYPE},
|
||||||
|
HeaderValue, Method
|
||||||
|
};
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() {
|
||||||
|
let app = route::create_route();
|
||||||
|
|
||||||
|
println!("🚀 Server started successfully");
|
||||||
|
let listener = tokio::net::TcpListener::bind("0.0.0.0:8500").await.unwrap();
|
||||||
|
axum::serve(listener, app).await.unwrap();
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
pub mod generic_response;
|
||||||
|
pub mod send_message;
|
||||||
@@ -1,5 +1,27 @@
|
|||||||
struct ReceivedMessage {
|
use chrono::NaiveDateTime;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use serde_with::serde_as;
|
||||||
|
use chrono::naive::serde::ts_seconds::deserialize as from_ts;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(Deserialize, Serialize)]
|
||||||
|
pub struct MessageAuthor {
|
||||||
|
name: String,
|
||||||
|
username: String,
|
||||||
|
email: String
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[serde_as]
|
||||||
|
#[derive(Deserialize, Serialize)]
|
||||||
|
pub struct SendMessage {
|
||||||
|
author: Option<MessageAuthor>,
|
||||||
|
|
||||||
subject: String,
|
subject: String,
|
||||||
|
|
||||||
message: String,
|
message: String,
|
||||||
timestamp: std::time,
|
|
||||||
|
#[serde(deserialize_with = "from_ts")]
|
||||||
|
timestamp: NaiveDateTime
|
||||||
}
|
}
|
||||||
13
src/route.rs
13
src/route.rs
@@ -0,0 +1,13 @@
|
|||||||
|
use axum::{
|
||||||
|
routing::{get, post},
|
||||||
|
Router
|
||||||
|
};
|
||||||
|
use crate::handler::health::{health_check};
|
||||||
|
use crate::handler::message::{send_message};
|
||||||
|
|
||||||
|
|
||||||
|
pub fn create_route() -> Router {
|
||||||
|
Router::new()
|
||||||
|
.route("/health", get(health_check))
|
||||||
|
.route("/message", post(send_message))
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user