
Security News
/Research
Popular node-ipc npm Package Infected with Credential Stealer
Socket detected malicious node-ipc versions with obfuscated stealer/backdoor behavior in a developing npm supply chain attack.
monster-fetch
Advanced tools
Request library for browsers, based on the Fetch API
![]() | ![]() | ![]() | ![]() | ![]() |
|---|---|---|---|---|
| Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ |
Using npm:
$ npm install monster-fetch
Using yarn:
$ yarn add monster-fetch
Using yarn:
$ yarn add monster-fetch
Using jsDelivr CDN:
<script src="https://cdn.jsdelivr.net/npm/monster-fetch/dist/fetch.min.js"></script>
Using unpkg CDN:
<script src="https://unpkg.com/monster-fetch/dist/fetch.min.js"></script>
Import Monster Fetch in your project
import MonsterFetch from 'monster-fetch'
Send a GET request
import MonsterFetch from 'monster-fetch'
// Send a request to get the user with the specified id
MonsterFetch("/user", { id: 123 })
.then(response => {
// request success, return Response Object
console.log(response)
})
.catch(error => {
// request error, return TypeError
console.log(error)
})
.finally(_ => {
// do something
})
// Use async/await to get the response
const getUser = async (id) => {
try {
const response = await MonsterFetch(`/user?id=${id}`)
console.log(response)
} catch (error) {
console.error(error)
}
}
Note The default request method of MonsterFetch is GET. When sending a GET request, you do not need to specify the request method. async/await syntactic sugar requires browser support to work
Send a POST request
MonsterFetch.post('/user', { username: "Monster Cone" })
.then(response => {
console.log(response)
})
.catch(error => {
console.log(error)
})
// Send a Post request
MonsterFetch('/user', { id: 123 }, {
method: "POST"
})
MonsterFetch.create([config])
const fetchApi = MonsterFetch.create({
baseUrl: "https://",
method: "GET",
mode: "cors",
timeout: 10000
})
The request address is required, the data is available, the request configuration is available, usually configured when creating an instance, so at the end of the parameters, we only need to pay attention to the URL and DATA
Options parameters are as follows
{
baseUrl: "", // Base Url, Will stitch in front of the URL.
method: "GET", // Request method
headers: {}, // Request headers
body: {}, // Request params
mode: "cors", // Request mode
credentials: "omit", // Whether the request carries cookies, the default is not carried
cache: "default", // Request cache mode
redirect: "follow", // Request redirect mode
timeout: 10000 // Timeout duration, in milliseconds
}
Note Except for Baseurl and Timeout parameters, other parameters are parameters of FETCH API. You can learn more from Browser Support to learn more
Return A Promise that resolves to a Response object.
Learn more from Response
MonsterFetch.defaultConfig.baseUrl = 'https://api.example.com/v1'
MonsterFetch.defaultConfig.headers = {
"Content-Type": "application/json"
}
const instance = MonsterFetch.create()
instance.defaultConfig.timeout = 60000
Add a interceptor
const instance = MonsterFetch.create()
instance.interceptors.request.use(config => { // config include url, body, options
// Process before sending requests
config.options = {
headers: {
Authorization: `Bearer xxxxxxxxx`
},
}
return config
})
instance.interceptors.response.use(async response => { // config include url, body, options
if (response.ok === true) {
const data = await response.json()
return data
} else {
return Promise.reject(response)
}
})
Clear interceptor
const instance = MonsterFetch.create();
instance.interceptors.request.use(() => {/*...*/});
instance.interceptors.request.clear(); // Removes interceptors from requests
You can also use multiple interceptors, which will be executed in the order of the use
const instance = MonsterFetch.create();
instance.interceptors.request.use(() => {/*...*/});
instance.interceptors.request.use(() => {/*...*/});
Fetch API supports the Signal option, and Monsterfetch is to cancel the request through this feature
const instance = MonsterFetch.create();
instance("/user", { id: 123 })
.then(response => {
console.log(response)
})
instance.cancel()
Note The Cancel method cancels all ongoing requests sent through the instance
FAQs
fetch package
We found that monster-fetch 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
/Research
Socket detected malicious node-ipc versions with obfuscated stealer/backdoor behavior in a developing npm supply chain attack.

Security News
TeamPCP and BreachForums are promoting a Shai-Hulud supply chain attack contest with a $1,000 prize for the biggest package compromise.

Security News
Packagist urges PHP projects to update Composer after a GitHub token format change exposed some GitHub Actions tokens in CI logs.