Skip to content

Commit

Permalink
Create api.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Dec 7, 2024
1 parent 11f5b76 commit 1b2f6cb
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/stablecoin/src/api.rs
Original file line number Diff line number Diff line change
@@ -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<String>) -> impl Responder {
HttpResponse::Ok().body(format!("Balance for user: {}", user))
}

0 comments on commit 1b2f6cb

Please sign in to comment.