
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.
@vpriem/rest-client
Advanced tools
A TypeScript rest api client based on node-fetch with type assertion.
yarn add @vpriem/rest-client
import { RestClient } from '@vpriem/rest-client';
interface Payload {
id: string;
}
const client = new RestClient('https://my.api');
await client.get<Payload>('/resource/{id}', { params: { id: 1 } });
This will perform a GET https://my.api/resource/1 request.
You can define your own client by extending the RestClient class in order to map your resources with methods and return types:
import { RestClient } from '@vpriem/rest-client';
interface BlogPost {
id: string;
title: string;
}
class BlogApi extends RestClient {
async getPost(id: string): Promise<BlogPost> {
return this.get<BlogPost>('/post/{id}', { params: { id } });
}
}
Now you can instantiate a client and send requests:
const blogApi = new BlogApi('https://blog.api');
await blogApi.getPost('859e3470-bcaa-499d-948f-0216e168e633');
This will perform a GET https://blog.api/post/859e3470-bcaa-499d-948f-0216e168e633 request.
For a complete client example see here.
import { RestClient } from '@vpriem/rest-client';
Instantiate a rest client.
url the base urloptions?.headers the default headers to send along with every requestPerform a basic request.
path path of the endpoint e.g /post/{id}options?.headers headers to send with the request, overriding default headersoptions?.params path parameters to replace in the pathoptions?.query query object, will be encoded and appended to the urloptions?.body body object, will be JSON encoded. A Content-Type: application/json header will be added to the requestPerform a GET request.
Perform a POST request.
Perform a PUT request.
Perform a DELETE request.
The request error thrown for http status < 200 or ≥ 300.
RequestError.message http status textRequestError.status http status codeRequestError.response node-fetch responseHelpful to handle 404 for example:
class BlogApi extends RestClient {
async getPost(id: string): Promise<BlogPost | null> {
try {
returnn await blogApi.getPost(id);
} catch (error) {
if (error instanceof RequestError && error.status === 404) {
return null;
}
throw error;
}
}
}
FAQs
A TypeScript rest api client based on node-fetch
The npm package @vpriem/rest-client receives a total of 0 weekly downloads. As such, @vpriem/rest-client popularity was classified as not popular.
We found that @vpriem/rest-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.