doc: api
This commit is contained in:
46
README.md
46
README.md
@@ -32,51 +32,11 @@ For an introduction to Codapi, see this post: [Interactive code examples for fun
|
|||||||
|
|
||||||
See [Installing Codapi](docs/install.md) for details.
|
See [Installing Codapi](docs/install.md) for details.
|
||||||
|
|
||||||
## Usage (API)
|
## Usage
|
||||||
|
|
||||||
Call `/v1/exec` to run the code in a sandbox:
|
See [API](docs/api.md) to run sandboxed code using the HTTP API.
|
||||||
|
|
||||||
```http
|
See [codapi-js](https://github.com/nalgeon/codapi-js) to embed the JavaScript widget into a web page.
|
||||||
POST https://api.codapi.org/v1/exec
|
|
||||||
content-type: application/json
|
|
||||||
|
|
||||||
{
|
|
||||||
"sandbox": "python",
|
|
||||||
"command": "run",
|
|
||||||
"files": {
|
|
||||||
"": "print('hello world')"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
`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.
|
|
||||||
|
|
||||||
`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).
|
|
||||||
|
|
||||||
Response:
|
|
||||||
|
|
||||||
```http
|
|
||||||
HTTP/1.1 200 OK
|
|
||||||
Content-Type: application/json
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
- `id` is the unique execution identifier.
|
|
||||||
- `ok` is `true` if the code executed without errors, or `false` otherwise.
|
|
||||||
- `duration` is the execution time in milliseconds.
|
|
||||||
- `stdout` is what the code printed to the standard output.
|
|
||||||
- `stderr` is what the code printed to the standard error, or a compiler/os error (if any).
|
|
||||||
|
|
||||||
## Usage (JavaScript)
|
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
## Contributing
|
|
||||||
|
|
||||||
Contributions are welcome. For anything other than bugfixes, please first open an issue to discuss what you want to change.
|
|
||||||
|
|
||||||
Be sure to add or update tests as appropriate.
|
|
||||||
|
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
|
|||||||
42
docs/api.md
Normal file
42
docs/api.md
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
# API
|
||||||
|
|
||||||
|
Call `/v1/exec` to run the code in a sandbox:
|
||||||
|
|
||||||
|
```http
|
||||||
|
POST https://api.codapi.org/v1/exec
|
||||||
|
content-type: application/json
|
||||||
|
|
||||||
|
{
|
||||||
|
"sandbox": "python",
|
||||||
|
"command": "run",
|
||||||
|
"files": {
|
||||||
|
"": "print('hello world')"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
`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.
|
||||||
|
|
||||||
|
`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).
|
||||||
|
|
||||||
|
Response:
|
||||||
|
|
||||||
|
```http
|
||||||
|
HTTP/1.1 200 OK
|
||||||
|
Content-Type: application/json
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
- `id` is the unique execution identifier.
|
||||||
|
- `ok` is `true` if the code executed without errors, or `false` otherwise.
|
||||||
|
- `duration` is the execution time in milliseconds.
|
||||||
|
- `stdout` is what the code printed to the standard output.
|
||||||
|
- `stderr` is what the code printed to the standard error, or a compiler/os error (if any).
|
||||||
|
-
|
||||||
|
|
||||||
|
- `id` is the unique execution identifier.
|
||||||
|
- `ok` is `true` if the code executed without errors, or `false` otherwise.
|
||||||
|
- `duration` is the execution time in milliseconds.
|
||||||
|
- `stdout` is what the code printed to the standard output.
|
||||||
|
- `stderr` is what the code printed to the standard error, or a compiler/os error (if any).
|
||||||
|
-
|
||||||
Reference in New Issue
Block a user