OneCompiler

OneCompiler APIs

730

Embedding Editor

OneCompiler's Editor can be embedded into 3rd party websites as an iFrame.
Following are the different options available to embed the editor

Embedding default editor

<iframe
 frameBorder="0"
 height="450px"  
 src="https://onecompiler.com/embed/" 
 width="100%"
 ></iframe>

Embedding a specific language

<iframe
 frameBorder="0"
 height="450px"  
 src="https://onecompiler.com/embed/python" 
 width="100%"
 ></iframe>

Embedding a code

<iframe
 frameBorder="0"
 height="450px"  
 src="https://onecompiler.com/embed/javascript/3wyne344h" 
 width="100%"
 ></iframe>

More options vis query parameters

Query ParameterDescription
availableLanguages=trueTo limit the languages in the Language selection popup
hideLanguageSelection=trueTo hide the language selection button
hideNew=trueTo hide the 'New' button

Capturing the code into parent website

Add the codeChangeEvent=true query param

<iframe 
 frameBorder="0" 
 height="450px"
 src="https://onecompiler.com/embed/python?codeChangeEvent=true"
 width="100%"
></iframe>

In the parent website catch the onmessage events. Following is the sample code to demonstrate

<script>
        window.onmessage = function (e) {
            if (e.data && e.data.language) {
                console.log(e.data)
                // handle the e.data which contains the code object
            }
        };
</script>

Demo

https://editor-demo.w3spaces.com/

API to run the code

Users can integrate the API from their backend servers and execute the code programatically.
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)"
    }
  ]
}'

Note: Replace the your_access_token with your account's access token. Reach out to [email protected] to get your acces token