How to Use the API
The API allows you to compile and execute Java code with optional arguments. Below is an example of how to interact with it.
Endpoint
POST /api/compile
Request Body
{
"code": "String",
"input": "String (optional)"
}
Response
{
"status": "success" | "error",
"message": "String (output or error details)",
"errors": [
{
"line": Number,
"message": "String"
}
]
}
Example
Use the following request with curl:
curl -X POST https://java-sandbox.sajitkhadka.com/api/compile \
-H "Content-Type: application/json" \
-d '{
"code": "public class Main { public static void main(String[] args) { System.out.println(\"Hello, World!\"); } }",
"input": ""
}'
Authentication
None. The API is free and needs no API key.
Rate Limits
Each client IP may send 30 requests per 30 seconds. Beyond that the API replies
with HTTP 429 Too Many Requests and {"error": "Too many requests. Please try again later."}.
Wait a few seconds and retry. Responses include X-RateLimit-Remaining and, on 429, Retry-After. Other limits: 5 second execution timeout, 64 KB of code, 64 KB of returned output, at most 100 whitespace-separated input values, and 4 programs running at once server-wide (HTTP 503 when busy). Missing code or no class gives HTTP 400; oversized code gives 413.
Examples
JavaScript
const res = await fetch("https://java-sandbox.sajitkhadka.com/api/compile", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ code: "public class Main { public static void main(String[] a){ System.out.println(1+1); } }" })
});
console.log(await res.json());
Python
import requests
r = requests.post("https://java-sandbox.sajitkhadka.com/api/compile",
json={"code": "public class Main { public static void main(String[] a){ System.out.println(1+1); } }"})
print(r.json())