From 1b2f6cbbe7bf1970fc0b4b5d0a07c476cb10fea9 Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Sat, 7 Dec 2024 17:09:26 +0700 Subject: [PATCH] Create api.rs --- src/stablecoin/src/api.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/stablecoin/src/api.rs diff --git a/src/stablecoin/src/api.rs b/src/stablecoin/src/api.rs new file mode 100644 index 0000000..f47376f --- /dev/null +++ b/src/stablecoin/src/api.rs @@ -0,0 +1,31 @@ +// src/api.rs +use actix_web::{web, HttpResponse, Responder}; + +pub async fn run_api() -> std::io::Result<()> { + HttpServer::new(|| { + App::new() + .route("/mint", web::post().to(mint)) + .route("/burn", web::post().to(burn)) + .route("/transfer", web::post().to(transfer)) + .route("/balance/{user}", web::get().to(get_balance)) + }) + .bind("127.0.0.1:8080")? + .run() + .await +} + +async fn mint() -> impl Responder { + HttpResponse::Ok().body("Minting functionality") +} + +async fn burn() -> impl Responder { + HttpResponse::Ok().body("Burning functionality") +} + +async fn transfer() -> impl Responder { + HttpResponse::Ok().body("Transfer functionality") +} + +async fn get_balance(web::Path(user): web::Path) -> impl Responder { + HttpResponse::Ok().body(format!("Balance for user: {}", user)) +}