
Product
Introducing Socket Scanning for VS Code Marketplace Extensions
Socket now scans VS Code extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.
This package contains a simple API-Client based on axios. IT provides a convenient way to make HTTP requests to various API endpoints, such as POST, GET, PUT, DELETE, and more.
The client is extended by the Harbor, Vault, and OAuth2 clients, which provide additional functionality specific to those services.
Table of Contents
npm install hapic --save
To create a configuration for the Client, a configuration must be specified,
like described in the following:
import { Client } from "hapic";
const client = new Client({
driver: {
baseURL: 'http://localhost:3000/',
withCredentials: true,
},
retry: false
});
In the upper example, the driver property is used to pass information to the underneath driver axios.
A singleton instance can be associated to a key, to handle multiple singleton instances.
Registration
import { Client, setClient } from "hapic";
const client = new Client({
//...
});
// This will register the client for the key "default",
// which is also the default key.
setClient(client, 'default');
Access
import { useClient } from 'hapic';
const client = useClient('default');
// do something with the client
DELETE
import client from 'hapic';
const { data } = await client.delete('users/1');
console.log(data);
// [{ id: 1, name: 'xxx' }]
GET
import client from 'hapic';
let { data } = await client.get('users');
console.log(data);
// [{ id: 2, name: 'Peter' }]
PATCH
import client from 'hapic';
let { data } = await client.patch('users/2', { name: 'Peter P.' });
console.log(data);
// [{ id: 2, name: 'Peter P.' }]
POST
import client from 'hapic';
let { data } = await client.post('users', { name: 'Hans' });
console.log(data);
// [{ id: 3, name: 'Hans' }]
PUT
import client from 'hapic';
let { data } = await client.put('users/3', { id: 3, name: 'Hans' });
console.log(data);
// [{ id: 3, name: 'Hans' }]
The main purpose of the header utils, is to parse and build HTTP headers.
AuthorizationHeader
import {
parseAuthorizationHeader,
stringifyAuthorizationHeader
} from "hapic";
const basicValue = Buffer
.from('admin:start123')
.toString('base64');
const value = parseAuthorizationHeader(`Basic ${basicValue}`);
console.log(value);
// {type: 'Basic', username: 'admin', password: 'start123'}
// -------------------------------------------------
let headerValue = stringifyAuthorizationHeader({
type: 'Basic',
username: 'admin',
password: 'start123'
});
console.log(headerValue);
// Basic xxxxxxx
headerValue = stringifyAuthorizationHeader({
type: 'Bearer',
token: 'start123'
});
console.log(headerValue);
// Bearer start123
Made with 💚
Published under MIT License.
FAQs
A http api client based on axios.
The npm package hapic receives a total of 2,050 weekly downloads. As such, hapic popularity was classified as popular.
We found that hapic demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.

Product
Socket now scans VS Code extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.

Research
/Security News
Socket uncovered two malicious VS Code themes in a GlassWorm-linked cluster with thousands of installs across VS Code Marketplace and Open VSX.

Security News
/Company News
Capital One is partnering with Socket to proactively secure its open source supply chain.