跳转至

获取 raw 文件

GET /api/v5/repos/{owner}/{repo}/raw/{path}

用户调用此接口,获取仓库中文件的 raw 原始内容,响应体为文件字节流。

访问令牌支持说明

  • AtomGit 用户访问令牌(AtomGit user access tokens)

是否允许匿名访问

此接口允许匿名访问

请求参数

参数名 位置 类型 必填 说明
owner path string 是 仓库所属空间地址(企业、组织或个人的地址 path)
repo path string 是 仓库路径(path)
path path string 是 文件的路径,对应 URL 中 raw/** 的 ** 段,特殊字符需转码
ref query string 否 分支、tag 或 commit(默认:仓库的默认分支)

响应参数

接口返回所请求文件的原始内容(字节流),响应体即为文件内容本身,无结构化 JSON 字段;返回的文件类型由所请求的文件决定。

失败响应

接口出错时由全局异常处理返回 JSON 错误信息,字段名以后端实际返回为准。

400 参数错误

{
  "error": "invalid_request",
  "message": "参数错误"
}

401 未认证

{
  "error": "unauthorized",
  "message": "缺少或无效的访问令牌"
}

404 文件不存在

{
  "error": "not_found",
  "message": "文件不存在"
}

HTTP 响应状态码

状态码 说明
200 成功(OK),返回文件原始内容
401 需要认证(Requires authentication)
403 禁止访问(Forbidden),无权限访问该仓库
404 仓库或文件不存在(Not found)
500 系统内部错误(Internal server error)

请求示例

参数说明

<owner> 替换为仓库所属空间地址(企业、组织或个人的地址 path); <repo> 替换为仓库路径(path); <path> 替换为文件路径,含多级目录时需转码(如 dir/file.md 中的 / 转码为 %2F); <ref> 替换为分支、tag 或 commit,不传时使用仓库的默认分支。

此接口允许匿名访问;如需访问私有仓库,可携带 AtomGit 用户访问令牌。

cURL

curl -X GET 'https://api.atomgit.com/api/v5/repos/<owner>/<repo>/raw/<path>?ref=<ref>'

JavaScript

// 原生 fetch (Node.js 18+ / 浏览器)
const response = await fetch("https://api.atomgit.com/api/v5/repos/<owner>/<repo>/raw/<path>?ref=<ref>");

if (!response.ok) {
  throw new Error(`请求失败: ${response.status}`);
}

const data = await response.text();
console.log(data);

Python

import requests

resp = requests.get(
    "https://api.atomgit.com/api/v5/repos/<owner>/<repo>/raw/<path>",
    params={"ref": "<ref>"},
    timeout=10,
)
resp.raise_for_status()

print(resp.text)

响应示例

状态码: 200

响应体为文件的原始内容,例如获取仓库中 README.md 的 raw 内容:

# My Repository

This is the raw content of the file.

错误码

错误码 说明
401 未认证或凭证无效(缺少/无效的访问凭证)
400 参数错误或请求无法解析
404 请求路径不存在
405 请求方法不支持
429 请求过于频繁,触发限流
500 系统内部错误

本页原文 Markdown:在 AtomGit 查看·内容源自开源项目 gitcode-dev/atomgit-api-doc