From e5627a4d6261adbd13be988d92705a1b24f40733 Mon Sep 17 00:00:00 2001 From: Baitinq Date: Fri, 21 Oct 2022 01:18:17 +0200 Subject: Indexer: Add skeleton http rest endpoint functionality /search and /resource endpoint. --- indexer/Cargo.toml | 2 ++ indexer/src/main.rs | 32 +++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) (limited to 'indexer') diff --git a/indexer/Cargo.toml b/indexer/Cargo.toml index 46846bd..3df1757 100644 --- a/indexer/Cargo.toml +++ b/indexer/Cargo.toml @@ -6,6 +6,8 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +actix-web = "*" +serde = { version = "1.0", features = ["derive"] } [[bin]] name = "indexer" diff --git a/indexer/src/main.rs b/indexer/src/main.rs index 33ec668..3418ef3 100644 --- a/indexer/src/main.rs +++ b/indexer/src/main.rs @@ -1,3 +1,33 @@ -fn main() { +use actix_web::{get, post, web, App, HttpServer, Responder}; +use serde::Deserialize; + +#[actix_web::main] +async fn main() -> std::io::Result<()> { println!("Hello, world! Im the indexer!"); + + serve_http_endpoint("127.0.0.1", 4444).await +} + +async fn serve_http_endpoint(address: &str, port: u16) -> std::io::Result<()> { + HttpServer::new(|| App::new().service(greet).service(add_resource)) + .bind((address, port))? + .run() + .await +} + +#[derive(Deserialize, Debug)] +struct Resource { + url: String, + content: String, +} + +#[post("/resource")] +async fn add_resource(resource: web::Json) -> impl Responder { + println!("Added resource! {:?}", resource); + format!("{:?}", resource) +} + +#[get("/search/{term}")] +async fn greet(term: web::Path) -> impl Responder { + format!("Searching for: {term}") } -- cgit 1.4.1