@hqoss/http-client
Advanced tools
Comparing version 0.1.9-0 to 0.1.10-0
@@ -10,2 +10,3 @@ /// <reference types="node" /> | ||
get: (pathOrUrl: string | URL, reqOpts?: RequestOptions | undefined) => Promise<IncomingMessage>; | ||
delete: (pathOrUrl: string | URL, reqOpts?: RequestOptions | undefined) => Promise<IncomingMessage>; | ||
post: (pathOrUrl: string | URL, body: Consumable, reqOpts?: RequestOptions | undefined) => Promise<IncomingMessage>; | ||
@@ -12,0 +13,0 @@ private write; |
@@ -22,2 +22,15 @@ "use strict"; | ||
}; | ||
this.delete = (pathOrUrl, reqOpts) => { | ||
const url = this.buildUrl(pathOrUrl); | ||
const opts = this.combineOpts(types_1.Method.Delete, reqOpts); | ||
return new Promise((resolve, reject) => { | ||
const req = http_1.request(url, opts) | ||
.once("error", reject) | ||
.once("response", resolve); | ||
if (this.willSendRequest) { | ||
this.willSendRequest(url, req); | ||
} | ||
return req.end(); | ||
}); | ||
}; | ||
this.post = async (pathOrUrl, body, reqOpts) => { | ||
@@ -40,2 +53,5 @@ const url = this.buildUrl(pathOrUrl); | ||
if (body instanceof stream_1.Readable) { | ||
// If there is an error reading data, | ||
// destroy the request and pass the error. | ||
body.once("error", req.destroy); | ||
// Pipe ends the writable stream (req) implicitly. | ||
@@ -60,3 +76,6 @@ // See https://nodejs.org/api/stream.html#stream_readable_pipe_destination_options. | ||
if (protocol !== "http:") { | ||
throw new Error(`only http protocol is supported, got ${protocol}`); | ||
throw new Error(` | ||
only http protocol is supported, got ${protocol} | ||
use HttpsClient for https, or Http2Client for http2 | ||
`); | ||
} | ||
@@ -69,4 +88,2 @@ const agent = new http_1.Agent({ keepAlive: true }); | ||
this.baseUrl = baseUrl; | ||
// @ts-ignore | ||
this.transformResponse = (res) => res; | ||
} | ||
@@ -73,0 +90,0 @@ } |
@@ -11,2 +11,3 @@ /// <reference types="node" /> | ||
get: (pathOrUrl: string | URL, reqOpts?: RequestOptions | undefined) => Promise<IncomingMessage>; | ||
delete: (pathOrUrl: string | URL, reqOpts?: RequestOptions | undefined) => Promise<IncomingMessage>; | ||
post: (pathOrUrl: string | URL, body: Consumable, reqOpts?: RequestOptions | undefined) => Promise<IncomingMessage>; | ||
@@ -13,0 +14,0 @@ private write; |
@@ -22,2 +22,15 @@ "use strict"; | ||
}; | ||
this.delete = (pathOrUrl, reqOpts) => { | ||
const url = this.buildUrl(pathOrUrl); | ||
const opts = this.combineOpts(types_1.Method.Delete, reqOpts); | ||
return new Promise((resolve, reject) => { | ||
const req = https_1.request(url, opts) | ||
.once("error", reject) | ||
.once("response", resolve); | ||
if (this.willSendRequest) { | ||
this.willSendRequest(url, req); | ||
} | ||
return req.end(); | ||
}); | ||
}; | ||
this.post = async (pathOrUrl, body, reqOpts) => { | ||
@@ -40,2 +53,5 @@ const url = this.buildUrl(pathOrUrl); | ||
if (body instanceof stream_1.Readable) { | ||
// If there is an error reading data, | ||
// destroy the request and pass the error. | ||
body.once("error", req.destroy); | ||
// Pipe ends the writable stream (req) implicitly. | ||
@@ -60,3 +76,6 @@ // See https://nodejs.org/api/stream.html#stream_readable_pipe_destination_options. | ||
if (protocol !== "https:") { | ||
throw new Error(`only https protocol is supported, got ${protocol}`); | ||
throw new Error(` | ||
only https protocol is supported, got ${protocol} | ||
use HttpClient for http, or Http2Client for http2 | ||
`); | ||
} | ||
@@ -69,4 +88,2 @@ const agent = new https_1.Agent({ keepAlive: true }); | ||
this.baseUrl = baseUrl; | ||
// @ts-ignore | ||
this.transformResponse = (res) => res; | ||
} | ||
@@ -73,0 +90,0 @@ } |
@@ -48,2 +48,11 @@ "use strict"; | ||
}); | ||
tests.set("performs DELETE request, gets back 202", async () => { | ||
const res = await httpClient.delete("/202"); | ||
const { headers, statusCode, statusMessage } = res; | ||
const resBuffer = await readableToBuffer(res); | ||
assert_1.default.equal(headers["x-method-ack"], "delete"); | ||
assert_1.default.equal(statusCode, 202); | ||
assert_1.default.equal(statusMessage, "Accepted"); | ||
assert_1.default.deepStrictEqual(resBuffer, Buffer.alloc(0)); | ||
}); | ||
tests.set("performs POST request with a string", async () => { | ||
@@ -50,0 +59,0 @@ const data = "fooBar"; |
@@ -15,3 +15,6 @@ import { Agent, IncomingMessage, RequestOptions, request } from "http"; | ||
if (protocol !== "http:") { | ||
throw new Error(`only http protocol is supported, got ${protocol}`); | ||
throw new Error(` | ||
only http protocol is supported, got ${protocol} | ||
use HttpsClient for https, or Http2Client for http2 | ||
`); | ||
} | ||
@@ -27,4 +30,2 @@ | ||
this.baseUrl = baseUrl; | ||
// @ts-ignore | ||
this.transformResponse = (res) => res; | ||
} | ||
@@ -52,2 +53,22 @@ | ||
delete = ( | ||
pathOrUrl: string | URL, | ||
reqOpts?: RequestOptions, | ||
): Promise<IncomingMessage> => { | ||
const url = this.buildUrl(pathOrUrl); | ||
const opts = this.combineOpts(Method.Delete, reqOpts); | ||
return new Promise((resolve, reject) => { | ||
const req = request(url, opts) | ||
.once("error", reject) | ||
.once("response", resolve); | ||
if (this.willSendRequest) { | ||
this.willSendRequest(url, req); | ||
} | ||
return req.end(); | ||
}); | ||
}; | ||
post = async ( | ||
@@ -85,2 +106,6 @@ pathOrUrl: string | URL, | ||
if (body instanceof Readable) { | ||
// If there is an error reading data, | ||
// destroy the request and pass the error. | ||
body.once("error", req.destroy); | ||
// Pipe ends the writable stream (req) implicitly. | ||
@@ -87,0 +112,0 @@ // See https://nodejs.org/api/stream.html#stream_readable_pipe_destination_options. |
@@ -16,3 +16,6 @@ import { IncomingMessage } from "http"; | ||
if (protocol !== "https:") { | ||
throw new Error(`only https protocol is supported, got ${protocol}`); | ||
throw new Error(` | ||
only https protocol is supported, got ${protocol} | ||
use HttpClient for http, or Http2Client for http2 | ||
`); | ||
} | ||
@@ -28,4 +31,2 @@ | ||
this.baseUrl = baseUrl; | ||
// @ts-ignore | ||
this.transformResponse = (res) => res; | ||
} | ||
@@ -53,2 +54,22 @@ | ||
delete = ( | ||
pathOrUrl: string | URL, | ||
reqOpts?: RequestOptions, | ||
): Promise<IncomingMessage> => { | ||
const url = this.buildUrl(pathOrUrl); | ||
const opts = this.combineOpts(Method.Delete, reqOpts); | ||
return new Promise((resolve, reject) => { | ||
const req = request(url, opts) | ||
.once("error", reject) | ||
.once("response", resolve); | ||
if (this.willSendRequest) { | ||
this.willSendRequest(url, req); | ||
} | ||
return req.end(); | ||
}); | ||
}; | ||
post = async ( | ||
@@ -86,2 +107,6 @@ pathOrUrl: string | URL, | ||
if (body instanceof Readable) { | ||
// If there is an error reading data, | ||
// destroy the request and pass the error. | ||
body.once("error", req.destroy); | ||
// Pipe ends the writable stream (req) implicitly. | ||
@@ -88,0 +113,0 @@ // See https://nodejs.org/api/stream.html#stream_readable_pipe_destination_options. |
{ | ||
"name": "@hqoss/http-client", | ||
"version": "0.1.9-0", | ||
"version": "0.1.10-0", | ||
"description": "A light-weight, performant, composable blueprint for writing consistent and re-usable Node.js HTTP clients", | ||
@@ -5,0 +5,0 @@ "main": "./dist/lib/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
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
161715
913