
Security News
Feross on TBPN: How North Korea Hijacked Axios
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.
@haul/http-client
Advanced tools
An abstraction on top of request-native-promise that makes functional composition easy.
Using npm:
> npm install @haul/http-client
Using yarn:
> yarn add @haul/http-client
import { createClient, base, headers } from '@haul/http-client';
// Initialize a http client
const googleClient = createClient(
// Set the baseurl to https://johndoe.com
base('https://johndoe.com'),
// Set user agent header
headers({ 'User-Agent': 'robot' }),
);
;(async async () => {
await googleClient('/some-page');
// You can also pass a request config specific for one request
await googleClient('/another-page', {
method: 'POST',
headers: { 'User-Agent': 'Not a robot' },
body: {
foo: 'bar'
}
})
})();
base(string)Configures base url for the client.
headers({ key: value })Configure header(s) for the client.
query({ key: value })Configure query string for the client.
The http-client relies heavily on middleware so the easiest way to extend behaviour is the create your own.
import { createClient, RequestConfig } from '@haul/http-client';
interface CustomRequestConfig extends RequestConfig {
myCustomProp: string;
}
export const myMiddleware = (myCustomProp: string) => (
opts: RequestConfig
): CustomRequestConfig => {
return {
...opts,
myCustomProp: myCcustomProp,
};
};
You can create more advanced middleware that is dependent on other values configured via other middleware:
export const myMiddleware = (myCustomProp: string) => (
opts: RequestConfig
): CustomRequestConfig => {
if (opts.headers && opts.headers['User-Agent'].toLowerCase() === 'robot') {
opts.headers = {
...opts.headers,
token: 'my robot token',
}
}
return opts;
};
Note that middleware is called in the order they are passed to createClient. If you need to access a property
defined from another middleware, your middleware must be called after.
FAQs
custom api on top of request promise native
The npm package @haul/http-client receives a total of 1 weekly downloads. As such, @haul/http-client popularity was classified as not popular.
We found that @haul/http-client demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.

Security News
OpenSSF has issued a high-severity advisory warning open source developers of an active Slack-based campaign using impersonation to deliver malware.

Research
/Security News
Malicious packages published to npm, PyPI, Go Modules, crates.io, and Packagist impersonate developer tooling to fetch staged malware, steal credentials and wallets, and enable remote access.