Skip to content

abhinav-nath/java-coderunner-api

Repository files navigation

Java CodeRunner API

This is a small Spring Boot app that exposes a REST API which can take Java code as request payload and execute it.

Start the app by running Application class.

Send a POST request to http://localhost:8080/execute with payload:

public class TempCode {
    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}
image

Your code will be executed and output will be printed to your console:

image


You can even execute fairly complex code like:

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class TempCode {
  public static void main(String[] args) {
    try {
      String city = "Pune";
      String urlString = "https://wttr.in/" + city + "?format=%l+weather+:+%C+%c+|+Temperature+%t+|+Feels+like+%f+|+Humidity+%h+|+Moon+phase+%m+|+Sunrise+%S+|+Sunset+%s\n";

      URL url = new URL(urlString);
      HttpURLConnection connection = (HttpURLConnection) url.openConnection();
      connection.setRequestMethod("GET");

      BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
      String inputLine;
      StringBuilder content = new StringBuilder();
      while ((inputLine = in.readLine()) != null) {
        content.append(inputLine);
      }
      in.close();
      connection.disconnect();

      // Print the weather data
      System.out.println("Weather Data: " + content.toString());
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}

image

The possibilities are endless! 😉

Disclaimer

This application is intended for fun and educational purposes only. It should never be used in real production environments. Executing arbitrary code can lead to malicious results, including security vulnerabilities and data breaches. Use this application at your own risk and ensure that it is run in a controlled and isolated environment. The developer is not responsible for any misuse or damage caused by the application.


⭐ Star this repository if it helped you!

About

A Spring Boot app that executes Java code from API payload

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages