diff options
author | Baitinq <manuelpalenzuelamerino@gmail.com> | 2022-10-21 01:18:17 +0200 |
---|---|---|
committer | Baitinq <manuelpalenzuelamerino@gmail.com> | 2022-10-21 11:29:27 +0200 |
commit | e5627a4d6261adbd13be988d92705a1b24f40733 (patch) | |
tree | 23449e4182bd521747ee1c9f9fb6457111949791 /indexer/src | |
parent | Crawler: Add Err string in the craw_url method (diff) | |
download | OSSE-e5627a4d6261adbd13be988d92705a1b24f40733.tar.gz OSSE-e5627a4d6261adbd13be988d92705a1b24f40733.tar.bz2 OSSE-e5627a4d6261adbd13be988d92705a1b24f40733.zip |
Indexer: Add skeleton http rest endpoint functionality
/search and /resource endpoint.
Diffstat (limited to 'indexer/src')
-rw-r--r-- | indexer/src/main.rs | 32 |
1 files changed, 31 insertions, 1 deletions
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<Resource>) -> impl Responder { + println!("Added resource! {:?}", resource); + format!("{:?}", resource) +} + +#[get("/search/{term}")] +async fn greet(term: web::Path<String>) -> impl Responder { + format!("Searching for: {term}") } |