Logo

Multi-file support for APIs

Compiler APIs simplify code management—upload, execute, and save seamlessly.

Multi-file support in compiler APIs enhances the processing and compilation of multiple interconnected source files. The workflow for multi-file compilation involves parsing individual files, analyzing dependencies to determine the correct compilation order, compiling each file considering these dependencies, and finally linking the compiled files to produce the executable or final output.

API usage workflow

  • Scenario 1: Upload project files and execute them at once.

image (13).png

  • Scenario 2: Upload project files, then execute in the next API call.

Screenshot 2024-01-04 at 10.42.00 am (1).png

  • Scenario 3: Upload project files and execute at once, then execute the existing file again.

image (15).png

Multi-file API endpoints

Endpoint | | Description | Type | |-----------|----| | Upload and execute project files at once | P | | Upload project files for next time execution | P | | Execute previously uploaded project files | P |

Upload and execute at once endpoint

 https://api.jdoodle.com/engine/execute-api-multifile

image (16).png

Input parameters

Parameter| Type| | Required | Description | |--------|-----------| | --- | --- client | | Yes | Your | | Yes | Your | | Yes | Programming language (e.g., “c99”) version | | Yes | Compiler version index multi | | Yes | Set to | | Optional | Libraries to include (e.g., [“pcre”]) main | | Optional | Standard input for the program |

Example request

curl -L \
  -X POST \
  -H 'Content-Type: application/json' \
  'https://api.jdoodle.com/v1/engine/execute-api-multifile' \
  -d '{"clientId":"your_client_id_here","clientSecret":"your_client_secret_here","language":"c99","versionIndex":5,"multiFile":True,"files":[{"name":"main.c","content":"#include <stdio.h>\nint main() { printf(\"Hello, World!\\n\"); return 0; }"}],"libs":["pcre"],"mainFile":"main.c","args":"","stdin":""}'

Response fields

Field| | Type | Description | |----|-----------| | string | Output from the executed program status | | integer | H | | string | Memory used during execution (in kilobytes) cpu | | string | C | | string | Unique identifier for the uploaded project files |

Response example

{
"output": "Pattern matched at offset 0\n",
"statusCode": 200,
"memory": "1920",
"cpuTime": "0.00",
"compilationStatus": None,
"projectKey": "32904e2a-c9be-4d84-a9c3-27b2cc8a2e2a"
}

Note : You can remove the “libs” field if no library is used, and “projectKey” can be used in the next execution API call.

Upload only endpoint

https://api.jdoodle.com/engine/execute-api-multifile-upload-only

image (17).png

Input Parameters

Parameter| Type| | Required | Description | |--------|-----------| | --- | --- client | | Yes | Your | | Yes | Your | | Yes | Programming language (e.g., “c99”) version | | Yes | Compiler version index multi | | Yes | Set to | | Yes | Array of file objects to upload |

Example request

curl -L \
  -X POST \
  -H 'Content-Type: application/json' \
  'https://api.jdoodle.com/v1/engine/execute-api-multifile-upload-only' \
  -d '{"clientId":"your_client_id_here","clientSecret":"your_client_secret_here","language":"c99","versionIndex":5,"multiFile":True,"files":[{"name":"main.c","content":"#include <stdio.h>\nint main() { printf(\"Hello, World!\\n\"); return 0; }"}]}'

Response Fields

Field| | Type | Description | |----|-----------| | string | Unique identifier for the uploaded project files |

Example response

{
"projectKey": "32904e2a-c9be-4d84-a9c3-27b2cc8a2e2a"
}

Execute existing file endpoint

 https://api.jdoodle.com/engine/execute-api-multifile-existing

Input parameters

Parameter| Type| | Required | Description | |--------|-----------| | --- | --- client | | Yes | Your | | Yes | Your | | Yes | Programming language (e.g., “c99”) version | | Yes | Compiler version index project | | Yes | Identifier of the previously uploaded project multi | | Yes | Set to | | Optional | Libraries to include (e.g., [“pcre”]) main | | Optional | Standard input for the program |

Example payload

{
"language": "c99",
"versionIndex": 5,
"projectKey": "projectKeyGoesHere", // the one from /execute-api-multifile-upload-only or /execute-api-multifile endpoint
"multiFile": True,
"libs": ["pcre"],
"mainFile": "main.c",
"args": "",
"stdin": "",
"hasInputFiles": False,
"clientId": "clientIdGoesHere",
"clientSecret": "clientIdGoesHere"
}

Response fields

Field| | Type | Description | |----|-----------| | string | Output from the executed program status | | integer | H | | string | Memory used during execution (in kilobytes) cpu | | string | C |

Example response

{
"output": "Pattern matched at offset 0\n",
"statusCode": 200,
"memory": "1664",
"cpuTime": "0.00",
"compilationStatus": None,
"projectKey": None
}