Skip to content

Commit 156e580

Browse files
committed
fixed documentation for /simple-execute and /execute
1 parent 2d80dad commit 156e580

1 file changed

Lines changed: 200 additions & 17 deletions

File tree

README.md

Lines changed: 200 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Using this API is designed to be as simple as possible, at it's core, it's just
1616
The following are the routes that this API makes available, click one to see it's documentation
1717

1818
<details>
19-
<summary><h3>POST Route: /simple-execute</h3></summary>
19+
<summary><h3>POST Route: /simple-execute (click to expand)</h3></summary>
2020

2121
This route is a drop in replacement for [CodeExecutionAPI](https://github.com/thealcodingclub/CodeExecutionAPI), just take the code where you called the old API and replace `https://codeapi.anga.codes/execute` with `${url}/simple-execute` and watch as ur response times get faster!.
2222

@@ -27,7 +27,6 @@ This route takes 4 fields:
2727
<summary>Click to see supported languages</summary>
2828

2929
- python
30-
- rust
3130
- cpp
3231
- c
3332
- java
@@ -38,9 +37,10 @@ This route takes 4 fields:
3837
3. `timeout` (optional field): The maximum number of seconds for which the code should run. If the code takes more time to execute than what it was allocated, it will be terminated.
3938
- default (value assumed if you dont specify): **5 seconds**
4039
- max (you can't allocate more seconds than this): **60 seconds**
41-
4. `max_memory`: The maximum memory in KB (kilobytes) that the code can use. If the code uses more memory than this, it will be terminated.
40+
4. `max_memory` (optional field): The maximum memory in KB (kilobytes) that the code can use. If the code uses more memory than this, it will be terminated.
4241
- default (value assumed if you dont specify): **32768KB** (or 32MB)
4342
- max (you can't allocate more RAM than this): **131072KB** (or 128MB)
43+
5. `inputs` (optional field): This is an array of strings where every element is 1 line, its completely optional and you should use it if your code reads input from STDIN (like with python input() or scanf() in C), read example 4 to see usage
4444

4545
*Note: the above mentioned default and max values can be modified by editing the environment variables mentioned at the bottom of this README*
4646

@@ -58,7 +58,7 @@ This route takes 4 fields:
5858
<summary>Click to copy curl command</summary>
5959

6060
```bash
61-
curl --location 'https://codeapi.anga.codes/execute' \
61+
curl --location '${url}/simple-execute' \
6262
--header 'Content-Type: application/json' \
6363
--data '{
6464
"language": "python",
@@ -75,7 +75,7 @@ curl --location 'https://codeapi.anga.codes/execute' \
7575
"output": "Hello World\n", // Output of the code
7676
"error": "", // If any error occurs during execution
7777
"memory_used": "13808 KB", // RAM used (in KB)
78-
"cpu_time": "125.034027ms" // in Seconds
78+
"cpu_time": "9.166097ms" // as in 9.16 milliseconds
7979
}
8080
```
8181

@@ -87,15 +87,15 @@ curl --location 'https://codeapi.anga.codes/execute' \
8787
{
8888
"language": "python",
8989
"code": "import time\nprint('Hello World')\ntime.sleep(5)",
90-
"timeout": 2, // in seconds (defaults to 5, max 60)
90+
"timeout": 2 // in seconds (defaults to 5, max 60)
9191
}
9292
```
9393

9494
<details>
9595
<summary>Click to copy curl command</summary>
9696

9797
```bash
98-
curl --location 'https://codeapi.anga.codes/execute' \
98+
curl --location '${url}/simple-execute' \
9999
--header 'Content-Type: application/json' \
100100
--data '{
101101
"language": "python",
@@ -113,7 +113,7 @@ curl --location 'https://codeapi.anga.codes/execute' \
113113
"output": "", // No output is returned on timeout
114114
"error": "Execution Timed Out", // Error message in case of timeout
115115
"memory_used": "15856 KB", // RAM used (in KB)
116-
"cpu_time": "2.000637132s" // Time before code was terminated
116+
"cpu_time": "2.00014463s" // Time before code was terminated
117117
}
118118
```
119119

@@ -133,7 +133,7 @@ curl --location 'https://codeapi.anga.codes/execute' \
133133
<summary>Click to copy curl command</summary>
134134

135135
```bash
136-
curl --location 'https://codeapi.anga.codes/execute' \
136+
curl --location '${url}/simple-execute' \
137137
--header 'Content-Type: application/json' \
138138
--data '{
139139
"language": "python",
@@ -149,9 +149,9 @@ curl --location 'https://codeapi.anga.codes/execute' \
149149
```json
150150
{
151151
"output": "",
152-
"error": "Traceback (most recent call last):\n File \"<string>\", line 1, in <module>\n File \"<string>\", line 1, in <listcomp>\nMemoryError\n",
153-
"memory_used": "283964 KB",
154-
"cpu_time": "803.820445ms"
152+
"error": "Memory limit exceeded", // code is terminated the moment it takes more memory than allocated
153+
"memory_used": "136636 KB",
154+
"cpu_time": "115.779962ms"
155155
}
156156
```
157157

@@ -174,7 +174,7 @@ curl --location 'https://codeapi.anga.codes/execute' \
174174
<summary>Click to copy curl command</summary>
175175

176176
```bash
177-
curl --location 'https://codeapi.anga.codes/execute' \
177+
curl --location '${url}/simple-execute' \
178178
--header 'Content-Type: application/json' \
179179
--data '{
180180
"language": "python",
@@ -194,8 +194,8 @@ curl --location 'https://codeapi.anga.codes/execute' \
194194
{
195195
"output": "first value entered is bob.\nsecond value entered is alice.\n",
196196
"error": "",
197-
"memory_used": "13400 KB",
198-
"cpu_time": "135.266682ms"
197+
"memory_used": "24504 KB",
198+
"cpu_time": "13.625964ms"
199199
}
200200
```
201201

@@ -205,7 +205,180 @@ curl --location 'https://codeapi.anga.codes/execute' \
205205
**Note**: the route `/simple-execute` also calls `/execute` under the hood, its just that the formatting for the input and output are slightly more easy to read and understand.
206206
<details>
207207
<summary><h3>POST Route: /execute</h3></summary>
208-
Will type this out soon
208+
209+
This route takes 4 fields:
210+
211+
1. `langauge`: The language of the code snippet.
212+
<details>
213+
<summary>Click to see supported languages</summary>
214+
215+
- python
216+
- cpp
217+
- c
218+
- java
219+
220+
</details>
221+
222+
2. `code`: The code snippet to be executed.
223+
3. `timeout` (optional field): The maximum number of **nanoseconds** for which the code should run. If the code takes more time to execute than what it was allocated, it will be terminated.
224+
- default (value assumed if you dont specify): **5 seconds**
225+
- max (you can't allocate more seconds than this): **60 seconds**
226+
4. `max_memory` (optional field): The maximum memory in KB (kilobytes) that the code can use. If the code uses more memory than this, it will be terminated.
227+
- default (value assumed if you dont specify): **32768KB** (or 32MB)
228+
- max (you can't allocate more RAM than this): **131072KB** (or 128MB)
229+
5. `inputs` (optional field): This is a single string that is fed to the code via STDIN at runtime, if you want multiple lines in STDIN then separate them with `\n`, its completely optional and you should use it if your code reads input from STDIN (like with python input() or scanf() in C), read example 4 to see usage
230+
231+
*Note: the above mentioned default and max values can be modified by editing the environment variables mentioned at the bottom of this README*
232+
233+
---
234+
235+
#### Request body format (Example 1):
236+
237+
```json
238+
{
239+
"language": "python",
240+
"code": "print('Hello World')"
241+
}
242+
```
243+
<details>
244+
<summary>Click to copy curl command</summary>
245+
246+
```bash
247+
curl --location '${url}/execute' \
248+
--header 'Content-Type: application/json' \
249+
--data '{
250+
"language": "python",
251+
"code": "print('\''Hello World'\'')"
252+
}'
253+
```
254+
255+
</details>
256+
257+
#### Response body format (Example 1):
258+
259+
```json
260+
{
261+
"output": "Hello World\n", // output from STDOUT
262+
"error": "", // output from STDERR
263+
"cpu_time": 10283909, // run time in nanoseconds (10ms or 0.01 seconds)
264+
"memory_used": 25116 // RAM used (in KB)
265+
}
266+
```
267+
268+
---
269+
270+
#### Request body format (Example 2):
271+
272+
```json
273+
{
274+
"language": "python",
275+
"code": "import time\nprint('Hello World')\ntime.sleep(5)",
276+
"timeout": 2000000000 // in nanoseconds (defaults to 5000000000, max 60000000000)
277+
}
278+
```
279+
280+
<details>
281+
<summary>Click to copy curl command</summary>
282+
283+
```bash
284+
curl --location '${url}/execute' \
285+
--header 'Content-Type: application/json' \
286+
--data '{
287+
"language": "python",
288+
"code": "import time\nprint('\''Hello World'\'')\ntime.sleep(5)",
289+
"timeout": 2000000000
290+
}'
291+
```
292+
293+
</details>
294+
295+
#### Response body format (Example 2):
296+
297+
```json
298+
{
299+
"output": "", // No output is returned on timeout
300+
"error": "Execution Timed Out", // Error message in case of timeout
301+
"cpu_time": 2000003280, // Time (in nanoseconds) before code was terminated
302+
"memory_used": 15856, // RAM used (in KB)
303+
}
304+
```
305+
306+
---
307+
308+
#### Request body format (Example 3):
309+
310+
```json
311+
{
312+
"language": "python",
313+
"code": "import random;[random.random() for x in range(10**7)]",
314+
"max_memory": 300000 // in KB (defaults to 32768, max 131072)
315+
}
316+
```
317+
318+
<details>
319+
<summary>Click to copy curl command</summary>
320+
321+
```bash
322+
curl --location '${url}/execute' \
323+
--header 'Content-Type: application/json' \
324+
--data '{
325+
"language": "python",
326+
"code": "import random;[random.random() for x in range(10**7)]",
327+
"max_memory": 300000
328+
}'
329+
```
330+
331+
</details>
332+
333+
#### Response body format (Example 3):
334+
335+
```json
336+
{
337+
"output": "",
338+
"error": "Memory limit exceeded", // code is terminated the moment it takes more memory than allocated
339+
"cpu_time": 116936122,
340+
"memory_used": 136628
341+
}
342+
```
343+
344+
---
345+
346+
#### Request body format (Example 4):
347+
348+
```json
349+
{
350+
"language": "python",
351+
"code": "a = input()\nprint(f'first value entered is {a}.')\nb=input()\nprint(f'second value entered is {b}.')",
352+
"inputs": "bob\nalice"
353+
}
354+
```
355+
356+
<details>
357+
<summary>Click to copy curl command</summary>
358+
359+
```bash
360+
curl --location '${url}/execute' \
361+
--header 'Content-Type: application/json' \
362+
--data '{
363+
"language": "python",
364+
"code": "a = input()\nprint(f'\''first value entered is {a}.'\'')\nb=input()\nprint(f'\''second value entered is {b}.'\'')",
365+
"inputs": "bob\nalice"
366+
}'
367+
```
368+
369+
</details>
370+
371+
#### Response body format (Example 4):
372+
373+
```json
374+
{
375+
"output": "first value entered is bob.\nsecond value entered is alice.\n",
376+
"error": "",
377+
"cpu_time": 9058716,
378+
"memory_used": 25136
379+
}
380+
```
381+
209382
</details>
210383

211384
## Environment Variables
@@ -237,4 +410,14 @@ curl --location 'https://codeapi.anga.codes/execute' \
237410
- `ENABLE_DEBUG`: if true, the server will expose debug routes (like `/check-ram`) for monitoring and debugging purposes
238411
- same format as `ENABLE_QUEUE`
239412
- by default this is `false`
240-
- the public API has this set to `true`
413+
- the public API has this set to `true`
414+
- `GIN_MODE`: wether to run the gonic-gin server in release mode or debug mode, for this API there wont be much of a performance difference regardless of which one you pick, it is reccomended that you read the docs for [gonic gin](https://gin-gonic.com/en/docs/deployment/#configuration-options) for more information
415+
- this can be set to `release` or `debug`
416+
- by default it is set to `debug`
417+
- the public API has this set to `release`
418+
- `PORT`: Which network port to run the server on
419+
- this can be set to any unsigned integer value between `0` and `65535`
420+
- by default this is `8080`
421+
- public API has this set to `8080`
422+
423+
**Note:** *if you are self-hosting this api, remember to run it with superuser permissions, or a user which has permissions to alter controlgroups and namespaces, normally you can achieve this just by using "sudo" before running the code*

0 commit comments

Comments
 (0)