API to run the code

Users can integrate the API from their backend servers and execute the code programmatically.
Following is the cURL to call the /run API to execute code

curl --location --request POST 'https://onecompiler.com/api/v1/run?access_token=your_access_token' \
--header 'Content-Type: application/json' \
--data-raw '{
  "language": "python",
  "stdin": "Peter",
  "files": [
    {
      "name": "HelloWorld.py",
      "content": "import sys\nname = sys.stdin.readline()\nprint('\''Hello '\''+ name)"
    }
  ]
}'

Response:

{
	"stdout": "Hello Peter\n",
	"stderr": null,
	"exception": null,
	"executionTime": 41,
	"limitPerMonthRemaining": 74694
	"status": "success",
}
FieldDescription
stdoutStandard output of the code execution
stderrStandard error of the code execution
exceptionException details during the code execution. Ex. Timeout/ Compilation failure etc.,
executionTimeTime taken to execute the code in milliseconds
limitPerMonthRemainingRemaining limit of the API calls in the API account
statusStatus of the API call (This does not indicate the code execution status)
errorError message in case of API Failure. This field return data when status: failed

status values: success/ failed (ex. API key is invalid/ API quota exceeded/ Invalid language id etc.,)

Common error scenarios and their responses:

API operation timedout:

{
    "status": "success",
    "error": "E001: operation timed out"
}

Exceeded rate limits:

{
    "status": "failed",
    "error": "E002: API quota exceeded"
}

Invalid API Token:

{
    "status": "failed",
    "error": "E003: invalid access_token"
}

Unsuppoted language:

{
    "status": "failed",
    "error": "E006: unsupported language flutter"
}

API to get the list of supported languages

http://onecompiler.com/api/v1/languages

Following are the list of supported languages and their ids

idnamelanguageTypeSupported Flags
adaAdaprogramming
assemblyAssemblyprogramming
backbonejsBackboneJSweb
bashBashprogramming
basicBasicprogramming
bootstrapBootstrapweb
brainfkBrainFKprogramming
bulmaBulmaweb
cCprogramming
csharpC#programming
cppC++programming
clojureClojureprogramming
cobolCobolprogramming
coffeescriptCoffeeScriptprogramming
commonlispCommonLispprogramming
dDprogramming
ejsEJSprogramming
elixirElixirprogramming
erlangErlangprogramming
fsharpF#programming
fortranFortranprogramming
foundationFoundationweb
goGoprogramming
groovyGroovyprogramming
haskellHaskellprogramming
htmlHTMLwebpersist
javaJavaprogramming
javascriptJavaScriptprogramming
jqueryJQueryweb
jshellJShellprogramming
kotlinKotlinprogramming
luaLuaprogramming
mariadbMariaDBdatabase
materializeMaterializeweb
sqlserverMicrosoft SQL Serverdatabase
milligramMilligramweb
mongodbMongoDBdatabase
mysqlMySQLdatabase--table, --tabbed, --vertical
nodejsNodeJSprogramming
objectivecObjective-Cprogramming
ocamlOCamlprogramming
octaveOctaveprogramming
oracleOracle Databasedatabase
plsqlOracle PL/SQLdatabase
paperCssPaperCSSweb
pascalPascalprogramming
perlPerlprogramming
phpPHPprogramming
postgresqlPostgreSQLdatabase
prologPrologprogramming
pythonPythonprogramming
python2Python2programming
rRprogramming
racketRacketprogramming
redisRedisdatabase
rubyRubyprogramming
rustRustprogramming
scalaScalaprogramming
semanticUISemantic UIweb
skeletonSkeletonweb
sqliteSQLitedatabase
swiftSwiftprogramming
tclTclprogramming
textTextprogramming
typescriptTypeScriptprogramming
uikitUikitweb
vbVisual Basic (VB.NET)programming

Flags

persist : To persist the output URL for 1 hour
--table : To display the output in table format
--tabbed : To display the output in tabbed format
--vertical : To display the output in vertical format

Batch execution

If you plan to run the same code with multiple STDIN values, which is common when executing test cases, the API supports passing stdin as an array. When an array of values is provided, the API executes the code multiple times, once for each stdin value, and returns a list of response objects corresponding to each execution.