# Compile API

Technically, it is possible to implement a parser (which is already done in the syntax highlighting module of code editor!) and corresponding code generation module in TypeScript to transform C0 to BC0 on browser.

However, to control the scale of this project, we decided to use the `cc0` compiler with `-b` to do this instead. We've set up a server to provide a `Compile API` for the frontend browser to call on.

## Compile C0 code into BC0 byte code

<mark style="color:green;">`POST`</mark> `URL: ...(backend not deployed on public server yet)/compile`

Accept multiple C0 source code files and&#x20;

On `Success`: response with a compiled BC0 byte code file.

On `Failure`: response with empty BC0 byte code and return the standard output from `cc0` compiler.

#### Query Parameters

| Name                                         | Type    | Description                                          |
| -------------------------------------------- | ------- | ---------------------------------------------------- |
| dyn\_check<mark style="color:red;">\*</mark> | boolean | Apply Dynamic Contract Check (-d flag in CC0) or not |

#### Request Body

| Name                                        | Type      | Description                                                                         |
| ------------------------------------------- | --------- | ----------------------------------------------------------------------------------- |
| filenames<mark style="color:red;">\*</mark> | String\[] | List of file names                                                                  |
| codes<mark style="color:red;">\*</mark>     | String\[] | Content (source codes) in each file, must have same length and order as `filenames` |

{% tabs %}
{% tab title="200: OK Almost in any situation" %}
```javascript
{
    "bytecode": string,    // Empty when compile failed
    "error": string        // Empty when compile successed
}
```
{% endtab %}

{% tab title="500: Internal Server Error Something's wrong in server side" %}
```javascript
{
    // Response
}
```
{% endtab %}
{% endtabs %}

