Rest API

bca-web is a web server that allows users to analyze source code through a REST API. This service is useful for anyone looking to perform code analysis over HTTP.

The server can be run on any host and port, and supports the following main functionalities:

  • Remove Comments from source code.
  • Retrieve Function Spans for given code.
  • Compute Metrics for the provided source code.

Running the Server

To run the server, you can use the following command:

bca-web --host 127.0.0.1 --port 9090
  • --host specifies the IP address where the server should run (default is 127.0.0.1).
  • --port specifies the port to be used (default is 8080).
  • -j specifies the number of parallel jobs (optional).

Endpoints

1. Ping the Server

Use this endpoint to check if the server is running.

Request:

GET http://127.0.0.1:8080/ping

Response:

  • Status Code: 200 OK
  • Body: empty.

Use curl -sf http://127.0.0.1:8080/ping && echo ok to script a liveness check — -f makes curl exit non-zero on any HTTP error.

2. Remove Comments

This endpoint removes comments from the provided source code. It accepts two Content-Type variants. Use application/octet-stream for raw byte-in / byte-out, and application/json for a JSON envelope.

Request:

POST http://127.0.0.1:8080/comment

Payload:

{
  "id": "unique-id",
  "file_name": "filename.ext",
  "code": "source code with comments"
}
  • id: A unique identifier for the request.
  • file_name: The name of the file being analyzed.
  • code: The source code with comments.

Response (JSON variant):

{
  "id": "unique-id",
  "code": [10, 112, 114, 105, 110, 116]
}

The code field is a byte array of the stripped source, not a string. Decode it with jq -r '.code | implode' (ASCII/UTF-8) or the equivalent in your client. The application/octet-stream variant returns the stripped source as the raw response body, which is simpler for shell pipelines.

3. Retrieve Function Spans

This endpoint retrieves the spans of functions in the provided source code.

Request:

POST http://127.0.0.1:8080/function

Payload:

{
  "id": "unique-id",
  "file_name": "filename.ext",
  "code": "source code with functions"
}
  • id: A unique identifier for the request.
  • file_name: The name of the file being analyzed.
  • code: The source code with functions.

Response:

{
  "id": "unique-id",
  "spans": [
    {
      "name": "function_name",
      "start_line": 1,
      "end_line": 10,
      "error": false
    }
  ]
}

error is true when the parser flagged the span as malformed (e.g. unbalanced delimiters inside the function body).

4. Compute Metrics

This endpoint computes various metrics for the provided source code.

Request:

POST http://127.0.0.1:8080/metrics

Payload:

{
  "id": "unique-id",
  "file_name": "filename.ext",
  "code": "source code for metrics"
  "unit": false
}
  • id: Unique identifier for the request.
  • file_name: The filename of the source code file.
  • code: The source code to analyze.
  • unit: A boolean value. true to compute only top-level metrics, false for detailed metrics across all units (functions, classes, etc.).

Response:

{
  "id": "unique-id",
  "language": "Rust",
  "spaces": {
    "metrics": {
      "cyclomatic_complexity": 5,
      "lines_of_code": 100,
      "function_count": 10
    }
  }
}