Gathering detailed insights and metrics for @octokit-next/request
Gathering detailed insights and metrics for @octokit-next/request
Gathering detailed insights and metrics for @octokit-next/request
Gathering detailed insights and metrics for @octokit-next/request
@octokit-next/request-error
Error class for Octokit request errors
@octokit-next/endpoint
Turns REST API endpoints into generic request options
@octokit-next/oauth-methods
Set of stateless request methods to create, check, reset, refresh, and delete user access tokens for OAuth and GitHub Apps
npm install @octokit-next/request
Typescript
Module System
Node Version
NPM Version
JavaScript (79.48%)
TypeScript (20.52%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
24 Stars
310 Commits
4 Forks
8 Watchers
5 Branches
17 Contributors
Updated on Jul 15, 2025
Latest Version
3.0.0
Package Id
@octokit-next/request@3.0.0
Unpacked Size
55.48 kB
Size
14.85 kB
File Count
11
NPM Version
10.9.2
Node Version
22.15.0
Published on
May 20, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
Send parameterized requests to GitHub’s APIs with sensible defaults in browsers and Node
@octokit-next/request
is a request library for modern JavaScript runtime environments (e.g. Browsers, Node, or Deno) that makes it easier
to interact with GitHub’s REST API and
GitHub’s GraphQL API.
It uses @octokit/endpoint
to parse
the passed options and sends the request using fetch
(node-fetch when the runtime has no native fetch
API).
🤩 1:1 mapping of REST API endpoint documentation, e.g. Add labels to an issue becomes
1request("POST /repos/{owner}/{repo}/issues/{number}/labels", { 2 owner: "octokit", 3 repo: "request.js", 4 number: 1, 5 labels: ["🐛 bug"], 6});
👶 Small bundle size (<4kb minified + gzipped)
😎 Authenticate with any of GitHubs Authentication Strategies.
👍 Sensible defaults
baseUrl
: https://api.github.com
headers.accept
: application/vnd.github.v3+json
headers.agent
: octokit-request.js/<current version> <OS information>
, e.g. octokit-request.js/1.2.3 Node.js/10.15.0 (macOS Mojave; x64)
👌 Simple to test: mock requests by passing a custom fetch method.
🧐 Simple to debug: Sets error.request
to request options causing the error (with redacted credentials).
Browsers |
Load @octokit-next/request directly from cdn.skypack.dev
|
---|---|
Node |
Install with
|
Deno |
Load
|
1// Following GitHub docs formatting: 2// https://docs.github.com/en/rest/repos/repos#list-organization-repositories 3const result = await request("GET /orgs/{org}/repos", { 4 headers: { 5 authorization: "token 0000000000000000000000000000000000000001", 6 }, 7 org: "octokit", 8 type: "private", 9}); 10 11console.log(`${result.data.length} repos found.`);
For GraphQL request we recommend using @octokit/graphql
. But in the end a GraphQL query is just a POST /graphql
request:
1const result = await request("POST /graphql", { 2 headers: { 3 authorization: "token 0000000000000000000000000000000000000001", 4 }, 5 query: `query ($login: String!) { 6 organization(login: $login) { 7 repositories(privacy: PRIVATE) { 8 totalCount 9 } 10 } 11 }`, 12 variables: { 13 login: "octokit", 14 }, 15});
method
& url
as part of optionsAlternatively, pass in a method and a url
1const result = await request({ 2 method: "GET", 3 url: "/orgs/{org}/repos", 4 headers: { 5 authorization: "token 0000000000000000000000000000000000000001", 6 }, 7 org: "octokit", 8 type: "private", 9});
The simplest way to authenticate a request is to set the Authorization
header directly, e.g. to a personal access token.
1const requestWithAuth = request.defaults({ 2 headers: { 3 authorization: "token 0000000000000000000000000000000000000001", 4 }, 5}); 6const result = await requestWithAuth("GET /user");
For more complex authentication strategies such as GitHub Apps, we recommend an authentication strategy plugin.
1// expects `APP_ID` and `PRIVATE_KEY` to be set. 2import { createAppAuth } from "@octokit/auth-app"; 3const auth = createAppAuth({ 4 appId: APP_ID, 5 privateKey: PRIVATE_KEY, 6 installationId: 123, 7}); 8const requestWithAuth = request.defaults({ 9 request: { 10 hook: auth.hook, 11 }, 12}); 13 14const { data: app } = await requestWithAuth("GET /app"); 15const { data: app } = await requestWithAuth( 16 "POST /repos/{owner}/{repo}/issues", 17 { 18 owner: "octocat", 19 repo: "hello-world", 20 title: "Hello from the engine room", 21 } 22);
request(route, options)
or request(options)
.
Options
name | type | description |
---|---|---|
route
| String |
**Required**. If route is set it has to be a string consisting of the request method and URL, e.g. GET /orgs/{org}
|
options.baseUrl
| String |
The base URL that route or url will be prefixed with, if they use relative paths. Defaults to https://api.github.com .
|
options.headers
| Object |
Custom headers. Passed headers are merged with defaults:headers['user-agent'] defaults to octokit-rest.js/1.2.3 (where 1.2.3 is the released version).headers['accept'] defaults to application/vnd.github.v3+json .Use options.mediaType.{format,previews} to request API previews and custom media types.
|
options.mediaType.format
| String | Media type param, such as `raw`, `html`, or `full`. See Media Types. |
options.mediaType.previews
| Array of strings | Name of GraphQL schema preview, e.g. `package-deletes` or `flash`. See Schema previews. |
options.method
| String |
Any supported http verb, case insensitive. Defaults to Get .
|
options.url
| String |
**Required**. A path or full URL which may contain :variable or {variable} placeholders,
e.g. /orgs/{org}/repos . The url is parsed using url-template.
|
options.data
| Any | Set request body directly instead of setting it to JSON based on additional parameters. See "The `data` parameter" below. |
options.request.agent
| http(s).Agent instance | Node only. Useful for custom proxy, certificate, or dns lookup. |
options.request.fetch
| Function | Custom replacement for built-in fetch method. Useful for testing or request hooks. |
options.request.hook
| Function |
Function with the signature hook(request, endpointOptions) , where endpointOptions are the parsed options as returned by endpoint.merge() , and request is request() . This option works great in conjuction with before-after-hook.
|
options.request.signal
| new AbortController().signal |
Use an AbortController instance to cancel a request. In node you can only cancel streamed requests.
|
options.request.log
|
object
|
Used for internal logging. Defaults to console .
|
options.request.timeout
| Number | Node only. Request/response timeout in ms, it resets on redirect. 0 to disable (OS limit applies). options.request.signal is recommended instead. |
All other options except options.request.*
will be passed depending on the method
and url
options.
url
, it will be used as replacement. For example, if the passed options are {url: '/orgs/{org}/repos', org: 'foo'}
the returned options.url
is https://api.github.com/orgs/foo/repos
method
is GET
or HEAD
, the option is passed as query parameterResult
request
returns a promise. If the request was successful, the promise resolves with an object containing 4 keys:
key | type | description |
---|---|---|
status | Integer | Response status status |
url | String | URL of response. If a request results in redirects, this is the final URL. You can send a HEAD request to retrieve it without loading the full response body. |
headers | Object | All response headers |
data | Any | The response body as returned from server. If the response is JSON then it will be parsed into an object |
If an error occurs, the promise is rejected with an error
object containing 3 keys to help with debugging:
error.status
The http response status codeerror.request
The request options such as method
, url
and data
error.response
The http response object with url
, headers
, and data
If the error is due to an AbortSignal
being used, the resulting AbortError
is bubbled up to the caller.
request.defaults()
Override or set default options. Example:
1import { request } from "@octokit-next/request"; 2const myrequest = request.defaults({ 3 baseUrl: "https://github-enterprise.acme-inc.com/api/v3", 4 headers: { 5 "user-agent": "myApp/1.2.3", 6 authorization: `token 0000000000000000000000000000000000000001`, 7 }, 8 org: "my-project", 9 per_page: 100, 10}); 11 12myrequest(`GET /orgs/{org}/repos`);
You can call .defaults()
again on the returned method, the defaults will cascade.
1const myProjectRequest = request.defaults({ 2 baseUrl: "https://github-enterprise.acme-inc.com/api/v3", 3 headers: { 4 "user-agent": "myApp/1.2.3", 5 }, 6 org: "my-project", 7}); 8const myProjectRequestWithAuth = myProjectRequest.defaults({ 9 headers: { 10 authorization: `token 0000000000000000000000000000000000000001`, 11 }, 12});
myProjectRequest
now defaults the baseUrl
, headers['user-agent']
,
org
and headers['authorization']
on top of headers['accept']
that is set
by the global default.
request.endpoint
See https://github.com/octokit/endpoint.js. Example
1const options = request.endpoint("GET /orgs/{org}/repos", { 2 org: "my-project", 3 type: "private", 4}); 5 6// { 7// method: 'GET', 8// url: 'https://api.github.com/orgs/my-project/repos?type=private', 9// headers: { 10// accept: 'application/vnd.github.v3+json', 11// authorization: 'token 0000000000000000000000000000000000000001', 12// 'user-agent': 'octokit/endpoint.js v1.2.3' 13// } 14// }
All of the @octokit/endpoint
API can be used:
octokitRequest.endpoint()
octokitRequest.endpoint.defaults()
octokitRequest.endpoint.merge()
octokitRequest.endpoint.parse()
data
parameter – set request body directlySome endpoints such as Render a Markdown document in raw mode don’t have parameters that are sent as request body keys, instead the request body needs to be set directly. In these cases, set the data
parameter.
1const response = await request("POST /markdown/raw", { 2 data: "Hello world github/linguist#1 **cool**, and #1!", 3 headers: { 4 accept: "text/html;charset=utf-8", 5 "content-type": "text/plain", 6 }, 7}); 8 9// Request is sent as 10// 11// { 12// method: 'post', 13// url: 'https://api.github.com/markdown/raw', 14// headers: { 15// accept: 'text/html;charset=utf-8', 16// 'content-type': 'text/plain', 17// 'user-agent': userAgent 18// }, 19// body: 'Hello world github/linguist#1 **cool**, and #1!' 20// } 21// 22// not as 23// 24// { 25// ... 26// body: '{"data": "Hello world github/linguist#1 **cool**, and #1!"}' 27// }
There are API endpoints that accept both query parameters as well as a body. In that case you need to add the query parameters as templates to options.url
, as defined in the RFC 6570 URI Template specification.
Example
1request( 2 "POST https://uploads.github.com/repos/octocat/Hello-World/releases/1/assets{?name,label}", 3 { 4 name: "example.zip", 5 label: "short description", 6 headers: { 7 "content-type": "text/plain", 8 "content-length": 14, 9 authorization: `token 0000000000000000000000000000000000000001`, 10 }, 11 data: "Hello, world!", 12 } 13);
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
16 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
packaging workflow detected
Details
Reason
SAST tool is run on all commits
Details
Reason
0 existing vulnerabilities detected
Reason
security policy file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 2
Details
Reason
Found 1/28 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
project is not fuzzed
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More