
Company News
Socket Named to Rising in Cyber 2026 List of Top Cybersecurity Startups
Socket was named to the Rising in Cyber 2026 list, recognizing 30 private cybersecurity startups selected by CISOs and security executives.
api-jarvis
Advanced tools
A lightweight assistant which helping you get data more easier.
Stop suffering from getting REST API data
v4.0.0v4.0.0
v3.7.0
getTimeoutErrorFormat(url, params) (thanks for GA-MO)v3.6.0
v3.5.0
v3.4.3
plugins to be default at undefined.v3.4.2
v3.4.0
v3.3.1
v3.2.1
v3.2.0
setDebugMode to set global debugger for fetchWithJarvis.v3.1.2
Doppy Srichairat'This project uses library ES2015 syntax, fetch and isomorphic-fetch. Let's checked it out.
$ npm install api-jarvis --save
$ yarn add api-jarvis
https://hlex.github.io/api-jarvis/demo
If you are newbie, PLEASE START HERE
import { fetchWithJarvis } from 'api-jarvis'
const data = getData().then((response) => {
console.log('data', response)
});
const getData = () => {
return fetchWithJarvis('http://httpstat.us/200')
.then((response, meta) => {
// get yours response
console.log(response, meta)
return response
})
}
import 'handleResponseCatchError' from api-jarvis at the top of your js file.
By default, api-jarvis using it own 'isResponseError' and 'toErrorFormat' plugins's function.
See default plugins function description
3.4.0No need to import handleResponseCatchError, It will be called in function fetchWithJarvis
import { fetchWithJarvis } from 'api-jarvis'
const data = getData().then((response) => {
console.log('data', response)
}).catch((error) => {
console.error('error', error)
})
export const getData = () => {
return fetchWithJarvis('http://httpstat.us/500')
.then((response, meta) => {
// get yours response
console.log(response, meta)
return response
})
}
Example for version prior 3.4.0
import { fetchWithJarvis, handleResponseCatchError } from 'api-jarvis'
const data = getData();
export const getData = () => {
return fetchWithJarvis('http://httpstat.us/500')
.then((response) => {
handleResponseCatchError(response) // this line automatically throw error if response has fault key
return response;
})
}
1. fetchWithJarvis (url, options, plugins)| Property | Type | Priority | Description |
|---|---|---|---|
| url | String | Required | url to fetch. |
| options | Object | Optional | Fetch options such as 'method', 'headers', etc. |
| plugins | PlugIns Schema | Optional | Plugins function to empower jarvis. (See Plugins Schema) |
return fetchWithJarvis()
2. handleResponseCatchError(response, isResponseError, toErrorFormat, meta)Let's me talk about handleResponseCatchError function a little bit
This function is used to check response is success or error to manage work flow easily.
Let's see in action.
| Property | Type | Priority | Description |
|---|---|---|---|
| response | Object | Required | Object to be parameters of isResponseError(response, meta) and toErrorFormat(response, meta) |
| isResponseError | Function | Optional | Function which consider should resove or reject. |
| toErrorFormat | Function | Optional | Fucntion which return error format for catch (error) {}. |
| meta | Object | Optional | Object to be parameters of isResponseError(response, meta) and toErrorFormat(response, meta) |
You might not want to send isError or convertFormat functions (as you seen, it is optional) so these are defaults
const isError = (response) => {
return response.fault !== undefined;
}
import { fetchWithJarvis, handleResponseCatchError } from 'api-jarvis'
const data = getData();
const myIsError = (response) => {
return response.indexOf('500') >= 0
}
export const getData = () => {
return fetchWithJarvis('http://httpstat.us/500')
.then((response) => {
handleResponseCatchError(response, myIsError)
return response
})
.catch((error) => {
console.error(error);
})
}
default class ApplicationError extends Error {
constructor({ type, trxId, processInstance, fault, displayMessages }) {
super(type);
this.type = type || 'ERROR';
this.trxId = trxId;
this.processInstance = processInstance;
this.code = fault.code;
this.fault = fault;
this.displayMessages = displayMessages;
this.message = {
th: displayMessages[0]['th-message'],
en: displayMessages[0]['en-message'],
technical: displayMessages[0]['technical-message'],
};
if (typeof Error.captureStackTrace === 'function') {
Error.captureStackTrace(this, this.constructor);
} else {
this.stack = (new Error(type)).stack;
}
}
}
const convertResponseToAppFormat = (response) => {
return new ApplicationError({
type: getErrorType(response),
trxId: response['trx-id'],
processInstance: response['process-instance'],
status: response.status,
fault: response.fault,
displayMessages: response['display-messages'],
});
};
import { fetchWithJarvis, handleResponseCatchError } from 'api-jarvis'
const data = getData();
const myConvertResponseToAppFormat = (response) => {
return {
code: Date.now(),
message: response,
}
}
const myIsError = (response) => {
return response.indexOf('500') >= 0
}
export const getData = () => {
return fetchWithJarvis('http://httpstat.us/500')
.then((response) => {
handleResponseCatchError(response, myIsError, myConvertResponseToAppFormat)
return response
})
.catch((error) => {
console.error(error);
})
}
API Jarvis is licensed under the MIT license
FAQs
api jarvis project
The npm package api-jarvis receives a total of 78 weekly downloads. As such, api-jarvis popularity was classified as not popular.
We found that api-jarvis 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
Socket was named to the Rising in Cyber 2026 list, recognizing 30 private cybersecurity startups selected by CISOs and security executives.

Research
Socket detected 84 compromised TanStack npm package artifacts modified with suspected CI credential-stealing malware.

Security News
A dispute over fsnotify maintainer access set off supply chain alarms around one of Go’s most widely used filesystem libraries.