Skip to content

omcoolkarni22/code-compiler-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Code Compiler API - Documentation

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:

  1. The API uses POST method for code compilation and the endpoint for compilation is https://flask-compiler-api.herokuapp.com/execute/v2/.
  2. The data required for compilation is source code, language, input, and timeout.
  3. You must name languages in this format C-> C, C++ -> CPP and Python -> PYTHON while sending a request.
  4. The datatypes of the post data must be source: str, language: str, input: str and timeout: int.
  5. Example Input:
    {source: 'i = int(input())\nj = int(input())\nprint(i,j)', language: 'PYTHON', testcases: '10\n10', timeout: 10}
  6. 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}
  7. You can use Postman or simply execute post.py file and make edits accordingly.

Output:

api-output.png

Installing in your Local System:

  1. The installation is only supported on Linux Based Machines and doesn't support Windows OS.
  2. Python must be installed in order to execute the API. Clone the repo using
    git clone https://github.com/omcoolkarni22/compiler-api.git
  3. Install the requirements.txt file using command
    pip install -r requirements.txt
  4. Once you are ready with installed requirements, you can directly execute
    python app.py or use flask environment variable export FLASK_APP=app and flask run
  5. The above command will start a development server on localhost port: 5000 and the app will be ready for use.

P.S.:

  1. GET methods are not supported by any means.
  2. You can add more languages of your choice.

Contributors are welcomed!

Releases

No releases published

Packages

No packages published

Languages