0

I am using GitHub API to fetch file from repo:

const octokit = new Octokit({
auth: "*******************************",
});

const response = await octokit.request(
  "GET /repos/owner/repo/contents/path",
  {
    owner: "owner",
    repo: "repo",
    path: "path",
  }
);

but I am getting response in base64 format. I need to add header Accept: application/vnd.github.VERSION.raw. Is there a way to add headers in Octokit request?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437

1 Answers1

0

You can register custom endpoint methods such as octokit.rest.repos.get() using the octokit.registerEndpoints(routes) method

octokit.registerEndpoints({
  foo: {
    bar: {
      method: "GET",
      url: "/repos/{owner}/{repo}/foo",
      headers: {
        accept: "application/vnd.github.VERSION+raw",
      },
      params: {
        ...
      },
    },
  },
});

octokit.foo.bar({
  owner: "octokit",
  repo: "rest.js",
  baz: "quz",
});

view more here Register Custom endpoint | octokit/rest.js documentation

  • I am already using octokit for another upload function, so not able to use octokit rest for this purpose. –  Aug 23 '22 at 09:52