@dnpr/make-request
Advanced tools
Comparing version 0.1.1 to 1.0.0
{ | ||
"name": "@dnpr/make-request", | ||
"version": "0.1.1", | ||
"version": "1.0.0", | ||
"description": "A simple HTTP/HTTPS agent for Node.js.", | ||
"main": "lib/index.js", | ||
"directories": { | ||
"example": "examples", | ||
"lib": "lib", | ||
"test": "test" | ||
}, | ||
"author": "dragonman225", | ||
"license": "MIT", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"scripts": { | ||
"test": "node test/make-request.js" | ||
"build": "npm run build:module && npm run build:doc", | ||
"build:module": "rm -rf dist && rollup -c && tsc --emitDeclarationOnly", | ||
"build:doc": "npm run build:typedoc && npm run build:dependency-graph", | ||
"build:typedoc": "typedoc --out typedoc --mode file src/", | ||
"build:dependency-graph": "npx depcruise --exclude '^(node_modules|src/interfaces)' --output-type dot --prefix 'https://github.com/dragonman225/notionapi-agent/tree/master/' src/index.ts | dot -T svg > documentation/dependency-graph.svg", | ||
"test": "ts-node test/index.spec.ts", | ||
"release": "npm run build && npm publish", | ||
"upgrade": "node tools/upgrade-deps.js" | ||
}, | ||
"devDependencies": { | ||
"@rollup/plugin-typescript": "^2.0.1", | ||
"@types/node": "^13.1.1", | ||
"@typescript-eslint/eslint-plugin": "^2.13.0", | ||
"@typescript-eslint/parser": "^2.13.0", | ||
"dependency-cruiser": "^6.1.0", | ||
"eslint": "^6.8.0", | ||
"rollup": "^1.27.14", | ||
"ts-node": "^8.5.4", | ||
"typescript": "^3.7.4", | ||
"zora": "^3.1.8" | ||
}, | ||
"files": [ | ||
"dist/" | ||
], | ||
"homepage": "https://github.com/dnpr/make-request", | ||
"repository": { | ||
@@ -18,11 +39,7 @@ "type": "git", | ||
}, | ||
"author": "dragonman225", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/dnpr/make-request/issues" | ||
}, | ||
"homepage": "https://github.com/dnpr/make-request", | ||
"devDependencies": { | ||
"eslint": "^6.6.0" | ||
} | ||
"typeScriptVersion": "3.7", | ||
"runkitExampleFilename": "" | ||
} |
@@ -19,36 +19,58 @@ # make-request | ||
```javascript | ||
const { makeHTTPSRequest } = require('@dnpr/make-request') | ||
```typescript | ||
import { makeRequest } from "@dnpr/make-request" | ||
const BASE_URL = 'httpbin.org' | ||
const USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36' | ||
const httpTarget = "http://httpbin.org" | ||
const httpsTarget = "https://httpbin.org" | ||
const USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36" | ||
const headers = { | ||
'accept': '*/*', | ||
'accept-encoding': 'gzip, deflate, br', | ||
'accept-language': 'en-US,en;q=0.9', | ||
'user-agent': USER_AGENT | ||
} | ||
async function main() { | ||
/** The same as options in NodeJS https.request() */ | ||
const httpsAgentOptions = { | ||
hostname: BASE_URL, | ||
port: 443, | ||
path: '/get', | ||
method: 'GET', | ||
headers | ||
} | ||
const headers = { | ||
"accept": "*/*", | ||
"accept-encoding": "gzip, deflate, br", | ||
"accept-language": "en-US,en;q=0.9", | ||
"user-agent": USER_AGENT | ||
} | ||
async function main() { | ||
const testBody = { | ||
message: "hello world" | ||
} | ||
try { | ||
let res = await makeHTTPSRequest(httpsAgentOptions) | ||
let resParsed = { | ||
statusCode: res.statusCode, | ||
data: JSON.parse(res.responseBuffer) | ||
} | ||
console.log(resParsed) | ||
} catch { | ||
/** A GET request with HTTP. */ | ||
const testHttp = makeRequest("GET", httpTarget + "/get")() | ||
console.log((await testHttp).data.toString()) | ||
/** A GET request with HTTPS. */ | ||
const testHttps = makeRequest("GET", httpsTarget + "/get")() | ||
console.log((await testHttps).data.toString()) | ||
/** A GET request with HTTPS and headers. */ | ||
const testHttpsHeader = | ||
makeRequest("GET", httpsTarget + "/get") | ||
.useHeaders(headers)() | ||
console.log((await testHttpsHeader).data.toString()) | ||
/** A POST request with JSON. */ | ||
const testJson = | ||
makeRequest("POST", "https://reqbin.com/echo/post/json") | ||
.useSerializer(JSON.stringify) | ||
.useDeserializer(JSON.parse)({ | ||
login: "login", password: "password" | ||
}) | ||
console.log((await testJson).data) | ||
/** A bad POST request with incorrectly serialized body. */ | ||
const testBadJson = | ||
makeRequest("POST", "https://reqbin.com/echo/post/json")(testBody) | ||
console.log((await testBadJson).data) | ||
} catch (error) { | ||
console.error(error) | ||
} | ||
} | ||
main() | ||
``` | ||
@@ -58,10 +80,14 @@ | ||
Clone the repository and setup. | ||
### Project Structure | ||
![project structure graph](documentation/dependency-graph.svg) | ||
### Setup | ||
```bash | ||
git clone https://github.com/dnpr/make-request.git | ||
npm install # or any package manager | ||
yarn install | ||
``` | ||
Run tests. | ||
### Run tests | ||
@@ -68,0 +94,0 @@ ```bash |
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
27965
13
710
0
94
10
5