feat: fetch from fosstodon (first) then serve on index

This commit is contained in:
Ayo Ayco 2025-08-26 20:49:47 +02:00
commit 732127076c
4 changed files with 2116 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/target

2079
Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

10
Cargo.toml Normal file
View file

@ -0,0 +1,10 @@
[package]
name = "cozy-discovery"
version = "0.1.0"
edition = "2024"
[dependencies]
actix-web = "4.0"
reqwest = { version = "0.11", features = ["json"] }
serde_json = "1.0.143"
tokio = { version = "1", features = ["full"] }

26
src/main.rs Normal file
View file

@ -0,0 +1,26 @@
// src/main.rs
use actix_web::{App, HttpResponse, HttpServer, Responder, web};
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| App::new().route("/", web::get().to(index)))
.bind("127.0.0.1:3000")
.unwrap()
.run()
.await
}
async fn index() -> impl Responder {
// Make GET request to the external API
let response = reqwest::get(
"https://fosstodon.org/api/v1/trends/statuses
",
)
.await
.unwrap();
// Get the response json
let json_response: serde_json::Value = response.json().await.unwrap();
web::Json(json_response)
}