Introduction:
The Code Compiler API is developed for the developer community and can be used to build online code compilers. This can be used with any Frontend Technology.
Currently, the API supports three languages mainly C, C++, and Python. The support for other languages will be added soon.
The REST-API is built using the combination of the latest technologies named Python, Flask, Flask-Restful API, subprocess, and OOPS concepts.
The production version is deployed to Heroku and can be accessed at here.
Using API:
- The API uses POST method for code compilation and the endpoint for compilation is https://flask-compiler-api.herokuapp.com/execute/v2/.
- The data required for compilation is source code, language, input, and timeout.
- You must name languages in this format C-> C, C++ -> CPP and Python -> PYTHON while sending a request.
- The datatypes of the post data must be source: str, language: str, input: str and timeout: int.
- Example Input:
{source: 'i = int(input())\nj = int(input())\nprint(i,j)', language: 'PYTHON', testcases: '10\n10', timeout: 10}
- Example Output:
{'Input': {'language': 'PYTHON', 'source': 'i = int(input())\nj = int(input())\nprint(i,j)', 'testcases': '10\n10', 'timeout': 10}, 'Output': {'ReturnCode': 0, 'stdout': '10 10\n', 'timeoutError': False}, 'Request Status Code': 200}
- You can use Postman or simply execute post.py file and make edits accordingly.
Installing in your Local System:
- The installation is only supported on Linux Based Machines and doesn't support Windows OS.
- Python must be installed in order to execute the API. Clone the repo using
git clone https://github.com/omcoolkarni22/compiler-api.git
- Install the requirements.txt file using command
pip install -r requirements.txt
- Once you are ready with installed requirements, you can directly execute
python app.py
or use flask environment variableexport FLASK_APP=app
andflask run
- The above command will start a development server on localhost port: 5000 and the app will be ready for use.
P.S.:
- GET methods are not supported by any means.
- You can add more languages of your choice.
Contributors are welcomed!