@octokit/request
Advanced tools
Comparing version 5.0.3 to 5.1.0
{ | ||
"name": "@octokit/request", | ||
"description": "Send parameterized requests to GitHub’s APIs with sensible defaults in browsers and Node", | ||
"version": "5.0.3", | ||
"version": "5.1.0", | ||
"license": "MIT", | ||
@@ -36,2 +36,3 @@ "files": [ | ||
"devDependencies": { | ||
"@octokit/auth-app": "^2.1.2", | ||
"@pika/pack": "^0.5.0", | ||
@@ -43,2 +44,3 @@ "@pika/plugin-build-node": "^0.6.0", | ||
"@types/jest": "^24.0.12", | ||
"@types/lolex": "^3.1.1", | ||
"@types/node": "^12.0.3", | ||
@@ -49,2 +51,3 @@ "@types/node-fetch": "^2.3.3", | ||
"jest": "^24.7.1", | ||
"lolex": "^4.2.0", | ||
"prettier": "^1.17.0", | ||
@@ -51,0 +54,0 @@ "semantic-release": "^15.10.5", |
@@ -52,2 +52,6 @@ # request.js | ||
👶 [Small bundle size](https://bundlephobia.com/result?p=@octokit/request@5.0.3) (\<4kb minified + gzipped) | ||
😎 [Authenticate](#authentication) with any of [GitHubs Authentication Strategies](https://github.com/octokit/auth.js). | ||
👍 Sensible defaults | ||
@@ -63,4 +67,2 @@ | ||
👶 Small bundle size (\<5kb minified + gzipped) | ||
## Usage | ||
@@ -115,2 +117,4 @@ | ||
For GraphQL request we recommend using [`@octokit/graphql`](https://github.com/octokit/graphql.js#readme) | ||
```js | ||
@@ -150,2 +154,41 @@ const result = await request("POST /graphql", { | ||
## Authentication | ||
The simplest way to authenticate a request is to set the `Authorization` header directly, e.g. to a [personal access token](https://github.com/settings/tokens/). | ||
```js | ||
const requestWithAuth = request.defaults({ | ||
headers: { | ||
authorization: "token 0000000000000000000000000000000000000001" | ||
} | ||
}); | ||
const result = await request("GET /user"); | ||
``` | ||
For more complex authentication strategies such as GitHub Apps or Basic, we recommend the according authentication library exported by [`@octokit/auth`](https://github.com/octokit/auth.js). | ||
```js | ||
const { createAppAuth } = require("@octokit/auth-app"); | ||
const auth = createAppAuth({ | ||
id: process.env.APP_ID, | ||
privateKey: process.env.PRIVATE_KEY, | ||
installationId: 123 | ||
}); | ||
const requestWithAuth = request.defaults({ | ||
request: { | ||
hook: auth.hook | ||
}, | ||
mediaType: { | ||
previews: ["machine-man"] | ||
} | ||
}); | ||
const { data: app } = await requestWithAuth("GET /app"); | ||
const { data: app } = await requestWithAuth("POST /repos/:owner/:repo/issues", { | ||
owner: "octocat", | ||
repo: "hello-world", | ||
title: "Hello from the engine room" | ||
}); | ||
``` | ||
## request() | ||
@@ -152,0 +195,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
52317
539
19