Skip to main content

Get tree

Retrieve the directory structure (tree) of a repository at a specific path and reference.
GET /api/tree

Parameters

owner
string
required
The username or organization name that owns the repository
repo
string
required
The repository name
ref
string
The branch, tag, or commit reference to retrieve the tree from. Defaults to the default branch if not specified
path
string
The directory path to retrieve. Defaults to the repository root if not specified

Response

Returns an array of tree entries representing files and directories.
type
string
Entry type: tree for directories or blob for files
path
string
Path to the file or directory
oid
string
Object ID (SHA-1 hash) of the tree or blob
mode
string
Git file mode (e.g., 100644 for regular files, 040000 for directories)

Example request

curl -X GET "https://api.gitflare.dev/api/tree?owner=johndoe&repo=my-project&ref=main&path=src"

Example response

[
  {
    "type": "tree",
    "path": "src/components",
    "oid": "a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0",
    "mode": "040000"
  },
  {
    "type": "blob",
    "path": "src/index.ts",
    "oid": "b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1",
    "mode": "100644"
  },
  {
    "type": "blob",
    "path": "src/app.ts",
    "oid": "c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1v2",
    "mode": "100644"
  }
]

Get blob

Retrieve the contents of a specific file (blob) from the repository.
GET /api/blob

Parameters

owner
string
required
The username or organization name that owns the repository
repo
string
required
The repository name
filepath
string
required
The path to the file relative to the repository root
ref
string
The branch, tag, or commit reference to retrieve the file from. Defaults to the default branch if not specified

Response

Returns an object containing the file content and metadata.
oid
string
Object ID (SHA-1 hash) of the blob
content
string
Base64-encoded file content
size
number
File size in bytes
isBinary
boolean
Whether the file is detected as binary content
highlightedHtml
string | null
Syntax-highlighted HTML version of the file content. Only available for non-binary, non-markdown files. Uses the github-dark-default theme

Example request

curl -X GET "https://api.gitflare.dev/api/blob?owner=johndoe&repo=my-project&filepath=src/index.ts&ref=main"

Example response

{
  "oid": "b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0u1",
  "content": "aW1wb3J0IHsgQXBwIH0gZnJvbSAnLi9hcHAnOwoKY29uc3QgYXBwID0gbmV3IEFwcCgpOwphcHAuc3RhcnQoKTs=",
  "size": 64,
  "isBinary": false,
  "highlightedHtml": "<pre class=\"shiki github-dark-default\" style=\"background-color:#0d1117;color:#e6edf3\" tabindex=\"0\"><code>...</code></pre>"
}

Usage notes

  • The content field contains the raw file content encoded as Base64. Decode it to get the original file content
  • For text files, the highlightedHtml field provides a ready-to-use syntax-highlighted HTML version using Shiki with the github-dark-default theme
  • Markdown files (.md, .mdx, .markdown) do not include syntax highlighting in highlightedHtml
  • Binary files have isBinary set to true and highlightedHtml set to null
  • If a file is not found, the endpoint returns a 404 error

Decoding content

To decode the Base64 content in JavaScript:
const decodedContent = atob(response.content);
Or in Node.js:
const decodedContent = Buffer.from(response.content, 'base64').toString('utf-8');

Build docs developers (and LLMs) love