Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
nexus-http
Advanced tools
nexus-http is a simple http client that allows you to make requests easily.
nexus-http
is a simple http client that allows you to make requests easily with fetch API.
npm i --save nexus-http
In a js
file remove the extra typing from the nexusHttp.get
part and .then
.
import { nexusHttp, HttpError, HttpResponse } from 'nexus-http';
nexusHttp.get<User[]>('http://localhost:3000/api/users', {
query: {
page: 1,
limit: 12,
deleted: false
}
})
.then((response: HttpResponse<User[]>) => {
// Add some logic when status is >= 200 and <= 299
})
.catch((response: HttpResponse<HttpError>) => {
// Add some logic on error
})
.finally(() => {
// Add some logic after success or error
});
With baseUrl:
import { nexusHttp, HttpError, HttpResponse } from 'nexus-http';
nexusHttp.setBaseUrl('http://localhost:3000/api/');
nexusHttp.get<User[]>('/users') // url before adding query params: http://localhost:3000/api/users
.then((response: HttpResponse<User[]>) => {
// Add some logic when status is >= 200 and <= 299
})
.catch((response: HttpResponse<HttpError>) => {
// Add some logic on error
})
.finally(() => {
// Add some logic after success or error
});
Create your own instance:
import { nexusHttp, HttpError, HttpResponse } from 'nexus-http';
const nexusHttp = new NexusHttp();
nexusHttp.get<User[]>('http://localhost:3000/api/users')
.then((response: HttpResponse<User[]>) => {
// Add some logic when status is >= 200 and <= 299
})
.catch((response: HttpResponse<HttpError>) => {
// Add some logic on error
})
.finally(() => {
// Add some logic after success or error
});
if fetch is not supported, the client use XmlClient by default.
import { nexusHttp, HttpError, HttpResponse, XmlClient } from 'nexus-http';
const nexusHttp = new NexusHttp();
nexusHttp.useClient(XmlClient);
// Now this instance of nexusHttp use the XmlClient (XMLHttpRequest)
nexusHttp.get<User[]>('http://localhost:3000/api/users')
.then((response: HttpResponse<User[]>) => {
// Add some logic when status is >= 200 and <= 299
})
.catch((response: HttpResponse<HttpError>) => {
// Add some logic on error
})
.finally(() => {
// Add some logic after success or error
});
FAQs
nexus-http is a simple http client that allows you to make requests easily.
We found that nexus-http 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
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.