Package Exports
- @dnpr/make-request
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@dnpr/make-request) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
make-request
A simple HTTP / HTTPS agent for Node.js.
Documentation
Installation
npm install @dnpr/make-requestUsage
import { makeRequest } from "@dnpr/make-request"
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"
async function main() {
const headers = {
"accept": "*/*",
"accept-encoding": "gzip, deflate, br",
"accept-language": "en-US,en;q=0.9",
"user-agent": USER_AGENT
}
const testBody = {
message: "hello world"
}
try {
/** 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()Development
Project Structure
Setup
git clone https://github.com/dnpr/make-request.git
yarn installRun tests
npm test