返回

从零入门:揭秘源代码文件 REST API(六)

后端

编译源代码文件

源代码文件 REST API 提供了编译源代码文件的方法,允许您一次编译多个文件。编译过程将根据您提供的配置生成可执行文件或库。

语法

POST /v1/projects/{project}/locations/{location}/sourceFiles:compile

请求体

{
  "sourceFiles": [
    "path/to/file1.js",
    "path/to/file2.js",
    ...
  ],
  "outputPath": "path/to/output.zip",
  "compilerOptions": {
    "language": "JAVASCRIPT",
    "version": "ES6",
    ...
  }
}

响应体

{
  "done": true,
  "result": {
    "outputPath": "path/to/output.zip"
  }
}

部署源代码文件

源代码文件 REST API 提供了部署源代码文件的方法,允许您将编译后的文件部署到目标环境。

语法

POST /v1/projects/{project}/locations/{location}/sourceFiles:deploy

请求体

{
  "sourceFile": "path/to/source.zip",
  "target": "projects/{project}/locations/{location}/services/{service}",
  "versionId": "12345"
}

响应体

{
  "done": true,
  "result": {
    "versionId": "12345"
  }
}

管理源代码文件

源代码文件 REST API 提供了管理源代码文件的方法,允许您查看、更新和删除源代码文件。

语法

GET /v1/projects/{project}/locations/{location}/sourceFiles/{source_file}
PUT /v1/projects/{project}/locations/{location}/sourceFiles/{source_file}
DELETE /v1/projects/{project}/locations/{location}/sourceFiles/{source_file}

请求体(PUT)

{
  "name": "path/to/source.zip",
  "content": "file content"
}

响应体(GET/PUT/DELETE)

{
  "name": "path/to/source.zip",
  "content": "file content"
}

监视源代码文件

源代码文件 REST API 提供了监视源代码文件的方法,允许您查看源代码文件的编译和部署状态。

语法

GET /v1/projects/{project}/locations/{location}/sourceFiles/{source_file}/operations

响应体

[
  {
    "name": "operation-id",
    "metadata": {
      "sourceFile": "path/to/source.zip",
      "target": "projects/{project}/locations/{location}/services/{service}"
    },
    "done": true,
    "result": {
      "versionId": "12345"
    }
  }
]

调试源代码文件

源代码文件 REST API 提供了调试源代码文件的方法,允许您在编译和部署源代码文件时设置断点并查看变量值。

语法

POST /v1/projects/{project}/locations/{location}/sourceFiles/{source_file}:debug

请求体

{
  "sourceFile": "path/to/source.zip",
  "target": "projects/{project}/locations/{location}/services/{service}",
  "versionId": "12345",
  "breakpoint": [
    {
      "file": "path/to/file.js",
      "line": 10
    }
  ]
}

响应体

{
  "done": true,
  "result": {
    "variables": [
      {
        "name": "x",
        "value": "10"
      }
    ]
  }
}

日志源代码文件

源代码文件 REST API 提供了日志源代码文件的方法,允许您查看编译和部署源代码文件时的日志。

语法

GET /v1/projects/{project}/locations/{location}/sourceFiles/{source_file}/logs

响应体

[
  {
    "timestamp": "2023-01-01T00:00:00Z",
    "severity": "INFO",
    "message": "Compilation successful"
  }
]