Skip to content

Commit 2a95a86

Browse files
committed
doc: api
1 parent e0b733b commit 2a95a86

2 files changed

Lines changed: 45 additions & 43 deletions

File tree

README.md

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -32,51 +32,11 @@ For an introduction to Codapi, see this post: [Interactive code examples for fun
3232

3333
See [Installing Codapi](docs/install.md) for details.
3434

35-
## Usage (API)
35+
## Usage
3636

37-
Call `/v1/exec` to run the code in a sandbox:
37+
See [API](docs/api.md) to run sandboxed code using the HTTP API.
3838

39-
```http
40-
POST https://api.codapi.org/v1/exec
41-
content-type: application/json
42-
43-
{
44-
"sandbox": "python",
45-
"command": "run",
46-
"files": {
47-
"": "print('hello world')"
48-
}
49-
}
50-
```
51-
52-
`sandbox` is the name of the pre-configured sandbox, and `command` is the name of a command supported by that sandbox. See [Adding a sandbox](docs/add-sandbox.md) for details on how to add a new sandbox.
53-
54-
`files` is a map, where the key is a filename and the value is its contents. When executing a single file, it should either be named as the `command` expects, or be an empty string (as in the example above).
55-
56-
Response:
57-
58-
```http
59-
HTTP/1.1 200 OK
60-
Content-Type: application/json
61-
62-
{
63-
"id": "python_run_9b7b1afd",
64-
"ok": true,
65-
"duration": 314,
66-
"stdout": "hello world\n",
67-
"stderr": ""
68-
}
69-
```
70-
71-
- `id` is the unique execution identifier.
72-
- `ok` is `true` if the code executed without errors, or `false` otherwise.
73-
- `duration` is the execution time in milliseconds.
74-
- `stdout` is what the code printed to the standard output.
75-
- `stderr` is what the code printed to the standard error, or a compiler/os error (if any).
76-
77-
## Usage (JavaScript)
78-
79-
See [codapi-js](https://github.com/nalgeon/codapi-js) to embed the JavaScript widget into a web page. The widget uses exactly the same API as described above.
39+
See [codapi-js](https://github.com/nalgeon/codapi-js) to embed the JavaScript widget into a web page.
8040

8141
## Contributing
8242

docs/api.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# API
2+
3+
Call `/v1/exec` to run the code in a sandbox:
4+
5+
```http
6+
POST https://api.codapi.org/v1/exec
7+
content-type: application/json
8+
9+
{
10+
"sandbox": "python",
11+
"command": "run",
12+
"files": {
13+
"": "print('hello world')"
14+
}
15+
}
16+
```
17+
18+
`sandbox` is the name of the pre-configured sandbox, and `command` is the name of a command supported by that sandbox. See [Adding a sandbox](docs/add-sandbox.md) for details on how to add a new sandbox.
19+
20+
`files` is a map, where the key is a filename and the value is its contents. When executing a single file, it should either be named as the `command` expects, or be an empty string (as in the example above).
21+
22+
Response:
23+
24+
```http
25+
HTTP/1.1 200 OK
26+
Content-Type: application/json
27+
28+
{
29+
"id": "python_run_9b7b1afd",
30+
"ok": true,
31+
"duration": 314,
32+
"stdout": "hello world\n",
33+
"stderr": ""
34+
}
35+
```
36+
37+
- `id` is the unique execution identifier.
38+
- `ok` is `true` if the code executed without errors, or `false` otherwise.
39+
- `duration` is the execution time in milliseconds.
40+
- `stdout` is what the code printed to the standard output.
41+
- `stderr` is what the code printed to the standard error, or a compiler/os error (if any).
42+
-

0 commit comments

Comments
 (0)