
Company News
/Security News
Socket Selected for OpenAI's Cybersecurity Grant Program
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.
@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
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.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.

Security News
Socket CEO Feross Aboukhadijeh joins 10 Minutes or Less, a podcast by Ali Rohde, to discuss the recent surge in open source supply chain attacks.

Research
/Security News
Campaign of 108 extensions harvests identities, steals sessions, and adds backdoors to browsers, all tied to the same C2 infrastructure.