Skip to content

Commit

Permalink
API call complete, response error
Browse files Browse the repository at this point in the history
  • Loading branch information
vrn21 committed Jan 6, 2024
1 parent bb1a8a2 commit b8df235
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/bin/temp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,35 @@ use std::collections::HashMap;
use reqwest;
use serde_json::json;

async fn run_async_code() -> Result<(), reqwest::Error> {
async fn compile_rust() -> Result<(), reqwest::Error> {
let code = "//hello world! I'm Krusty the Krab and i like money lol. \n \n//Insert your rusty code over here and i will do the rest\n \n//Also,I tell NO to code that asks input from user \n \n \nfn main(){\n println!(6969696); //write code here\n}";
let url = "https://play.rust-lang.org/execute";
let url = "https://play.rust-lang.org/compile";

let mut data = HashMap::new();
data.insert("channel", "stable");
data.insert("mode", "debug");
data.insert("edition", "2024");
data.insert("edition", "2021");
data.insert("crateType", "bin");
data.insert("code", code);

let client = reqwest::Client::new();

let res = client.post(url)
.header(reqwest::header::CONTENT_TYPE, "application/json")
.body(json!(data).to_string()) // Convert the HashMap to serde_json::Value using json!()
.send()
.await?;
.header(reqwest::header::CONTENT_TYPE, "application/json")
.json(&json!(data)) // Convert the HashMap to serde_json::Value using json!()
.send()
.await?;

println!("{:?}", res);


// Handle the response here
println!("{:?}", res);

Ok(())
}

#[tokio::main]
async fn main() {
if let Err(err) = run_async_code().await {
if let Err(err) = compile_rust().await {
// Handle the error here
eprintln!("Error: {:?}", err);
}
Expand Down

0 comments on commit b8df235

Please sign in to comment.