[feat] introduced server
and cli
crates with foundational HTTP server and CLI implementation, including routing, health check, and configuration setup
This commit is contained in:
@@ -1,28 +1,16 @@
|
||||
[package]
|
||||
name = "owly-news-api"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
|
||||
[lib]
|
||||
path = "src/lib.rs"
|
||||
name = "api"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
anyhow = { workspace = true }
|
||||
tokio = { workspace = true, features = ["full"] }
|
||||
axum = { workspace = true }
|
||||
serde = { workspace = true, features = ["derive"] }
|
||||
serde = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
sqlx = { workspace = true, features = ["runtime-tokio", "tls-native-tls", "sqlite", "macros", "migrate", "chrono", "json"] }
|
||||
dotenv = { workspace = true }
|
||||
tracing = { workspace = true }
|
||||
tracing-subscriber = { workspace = true, features = ["env-filter", "json"] }
|
||||
once_cell = { workspace = true }
|
||||
toml = { workspace = true }
|
||||
unicode-segmentation = { workspace = true }
|
||||
sha2 = { workspace = true }
|
||||
hex = { workspace = true }
|
||||
readability = { workspace = true }
|
||||
scraper = { workspace = true }
|
||||
tracing = { workspace = true }
|
||||
async-trait = "0.1.89"
|
||||
|
||||
[dev-dependencies]
|
||||
tokio-test = { workspace = true }
|
||||
axum-test = { workspace = true }
|
||||
[features]
|
||||
default = []
|
||||
|
57
backend-rust/crates/api/src/config.rs
Normal file
57
backend-rust/crates/api/src/config.rs
Normal file
@@ -0,0 +1,57 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Deserialize, Serialize, Debug, Clone)]
|
||||
#[serde(default)]
|
||||
pub struct Cli {
|
||||
#[serde(default)]
|
||||
pub default_output: DefaultOutput,
|
||||
#[serde(default = "Cli::default_pager_command")]
|
||||
pub pager_command: String,
|
||||
#[serde(default = "Cli::default_show_progress")]
|
||||
pub show_progress: bool,
|
||||
#[serde(default = "Cli::default_auto_confirm_bulk")]
|
||||
pub auto_confirm_bulk: bool,
|
||||
#[serde(default = "Cli::default_show_geographic_hierarchy")]
|
||||
pub show_geographic_hierarchy: bool,
|
||||
}
|
||||
|
||||
impl Default for Cli {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
default_output: DefaultOutput::Table,
|
||||
pager_command: Self::default_pager_command(),
|
||||
show_progress: Self::default_show_progress(),
|
||||
auto_confirm_bulk: Self::default_auto_confirm_bulk(),
|
||||
show_geographic_hierarchy: Self::default_show_geographic_hierarchy(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, Debug, Clone)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum DefaultOutput {
|
||||
Table,
|
||||
Json,
|
||||
}
|
||||
|
||||
impl Default for DefaultOutput {
|
||||
fn default() -> Self {
|
||||
DefaultOutput::Table
|
||||
}
|
||||
}
|
||||
|
||||
impl Cli {
|
||||
pub fn default_pager_command() -> String {
|
||||
// Example default; customize as needed
|
||||
"less -R".to_string()
|
||||
}
|
||||
pub fn default_show_progress() -> bool {
|
||||
true
|
||||
}
|
||||
pub fn default_auto_confirm_bulk() -> bool {
|
||||
false
|
||||
}
|
||||
pub fn default_show_geographic_hierarchy() -> bool {
|
||||
true
|
||||
}
|
||||
}
|
@@ -1,2 +1,5 @@
|
||||
pub mod api;
|
||||
pub use api::*;
|
||||
//! API-first core: shared types, DTOs, service traits, configuration.
|
||||
|
||||
pub mod config;
|
||||
pub mod types;
|
||||
pub mod services;
|
18
backend-rust/crates/api/src/services.rs
Normal file
18
backend-rust/crates/api/src/services.rs
Normal file
@@ -0,0 +1,18 @@
|
||||
use crate::types::Health;
|
||||
use async_trait::async_trait;
|
||||
|
||||
// Implement your service traits here. Example:
|
||||
#[async_trait]
|
||||
pub trait HealthService: Send + Sync {
|
||||
async fn health(&self) -> Health;
|
||||
}
|
||||
|
||||
// A trivial default implementation that can be used by server and tests.
|
||||
pub struct DefaultHealthService;
|
||||
|
||||
#[async_trait]
|
||||
impl HealthService for DefaultHealthService {
|
||||
async fn health(&self) -> Health {
|
||||
Health { status: "ok".into() }
|
||||
}
|
||||
}
|
6
backend-rust/crates/api/src/types.rs
Normal file
6
backend-rust/crates/api/src/types.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Health {
|
||||
pub status: String,
|
||||
}
|
Reference in New Issue
Block a user