GitHub REST API Delphi Client via sgcOpenAPI

GitHub maintains the largest publicly available OpenAPI description — over 1,000 endpoints across repositories, issues, pull requests, actions, checks, packages and the GraphQL gateway. Feed it into sgcOpenAPI and emit a typed Delphi unit that your application can use to drive any GitHub workflow that the REST API exposes.

GitHub + sgcOpenAPI

GitHub ships a fully maintained OpenAPI 3 description under the MIT licence. sgcOpenAPI parses it and emits a single Pascal unit that compiles on Delphi 7 through RAD Studio 13.

Auth

Personal access token, GitHub App JWT, OAuth

Generated unit

sgcOpenAPI_GitHub

Platforms

Windows, macOS, Linux, iOS, Android

Generate the client

GitHub publishes two flavours of the spec — api.github.com.json for the public hosted service and ghes-3.x.json for GitHub Enterprise Server. Point the parser at the one you target.

uses
  sgcOpenAPI_Parser, sgcOpenAPI_Generator;

var
  vParser: TsgcOpenAPIParser;
  vGen: TsgcOpenAPIGenerator;
begin
  vParser := TsgcOpenAPIParser.Create(nil);
  try
    vParser.LoadFromFile('C:\specs\github\api.github.com.json');
    Memo1.Lines.Add(Format('GitHub spec: %d paths, %d schemas',
      [vParser.Paths.Count, vParser.Schemas.Count]));

    vGen := TsgcOpenAPIGenerator.Create(nil);
    try
      vGen.Parser := vParser;
      vGen.OutputUnit := 'sgcOpenAPI_GitHub';
      vGen.OutputFolder := 'C:\Generated\GitHub';
      vGen.GroupBy := gbTag;        // one class per tag
      vGen.Generate;
    finally
      vGen.Free;
    end;
  finally
    vParser.Free;
  end;
end;

The generator emits one class per GitHub tag — TsgcGitHub_Repos, TsgcGitHub_Issues, TsgcGitHub_Pulls, TsgcGitHub_Actions, TsgcGitHub_Checks, TsgcGitHub_Packages, TsgcGitHub_OrgsAdmin and so on — all owned by a top-level TsgcGitHub facade.

List repositories

Authenticate with a personal access token, then enumerate the repositories of the current user. Pagination is handled by the generated enumerable wrapper — just for...in over the result and the client fetches additional pages on demand.

uses sgcOpenAPI_GitHub;

var
  vGH: TsgcGitHub;
  vRepo: TsgcGitHubRepository;
begin
  vGH := TsgcGitHub.Create(nil);
  try
    vGH.Token := 'ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxx';
    vGH.UserAgent := 'sgcDelphi/1.0';

    for vRepo in vGH.Repos.ListForAuthenticatedUser(
      Visibility := 'private', PerPage := 100) do
    begin
      Memo1.Lines.Add(Format('%s — %s',
        [vRepo.FullName, vRepo.Description]));
    end;
  finally
    vGH.Free;
  end;
end;

Create an issue and review a pull request

Two short calls — one mutating, one reading. Both routes return the same strongly typed objects that the spec describes.

// Create an issue in repo "octocat/Hello-World"
var
  vIssue: TsgcGitHubIssue;
begin
  vIssue := vGH.Issues.Create(
    Owner := 'octocat',
    Repo  := 'Hello-World',
    Title := 'Memory leak in HTTP/2 reader',
    Body  := 'Repro steps: ...',
    Labels := ['bug', 'http2']);
  ShowMessage('Filed issue #' + IntToStr(vIssue.Number));

  // List open PRs and inspect the head ref
  for vPR in vGH.Pulls.List(
    Owner := 'octocat', Repo := 'Hello-World',
    State := 'open', Sort := 'updated') do
  begin
    Memo1.Lines.Add(Format('PR #%d %s — %s',
      [vPR.Number, vPR.Title, vPR.Head.Ref]));
  end;
end;

What the generated unit gives you

Every tag in the official OpenAPI description becomes a typed class. Every documented parameter becomes a typed argument.

Repositories & content

Repos, Git, Contents, Branches, Tags, Releases, Forks. Read, write and delete files. Create branches, manage protection rules, draft and publish releases.

Issues & pull requests

Issues, Pulls, Reviews, Comments, Reactions, Labels, Milestones, Assignees. The full collaboration surface.

Actions & checks

Actions, WorkflowRuns, WorkflowJobs, Artifacts, Secrets, Variables, Checks, CheckRuns, CheckSuites — build dashboards or run automation off GitHub Actions data.

Packages & container registry

Packages, PackageVersions — manage npm, NuGet, Maven, RubyGems and container packages from Delphi.

Organisations & teams

Orgs, Teams, Members, Memberships, OrgsAdmin for owner-only operations like SCIM provisioning.

GitHub Apps

Apps, Installations, AppManifests — install GitHub Apps programmatically and mint short-lived installation tokens.

Three things to watch for

Rate limits and conditional requests

GitHub enforces an hourly rate limit (5,000 requests/hour with a token, 60 unauthenticated). The generated client stores the last ETag for every GET response — reuse them by setting IfNoneMatch on the next call to get a free 304 response.

GitHub Apps need short-lived tokens

For GitHub App installations you exchange a JWT (signed with your app's private key) for a 1-hour installation token. Use the Apps.CreateInstallationAccessToken method and refresh the token before it expires.

Polymorphic timeline events

The Issues.ListEventsForTimeline endpoint returns a discriminated union of dozens of event types. The generated unit emits a base class and one descendant per variant — downcast based on the Event property.

From the blog

OpenAPI Delphi parser

How the underlying parser handles real-world OpenAPI 3.x specifications.

Read post →

OpenAPI client + parser

The companion blog post that introduces both the client wrapper and the parser internals.

Read post →

sgcOpenAPI 2026.6

Latest release notes — new generator options and parser fixes.

Read post →

Build your GitHub automation today

sgcOpenAPI ships the parser, code generator, OpenAPI server and the Amazon, Google, Microsoft and Azure SDK bundles — one product, three tiers.