Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
fetch-mocker
Advanced tools
mocker for fetch requests in browser
npm install fetch-mocker
import Mocker from "fetch-mocker"
const mocker = new Mocker()
mocker.requestDelay = 1000
let persons = [
{ id : "1", civility : "mister", firstName : "Jean", lastName : "Dupont" },
{ id : "2", civility : "madame", firstName : "Catherine", lastName : "Durand" },
{ id : "3", civility : "mister", firstName : "Jean-Pierre", lastName : "Martin" }]
mocker.get("/api/persons", () => persons)
const findPerson = id => persons.find(item => item.id === id)
mocker.get("/api/persons/:id", request => {
const id = request.params.id
const person = findPerson(id)
return person ? person : mocker.makeResponse("Unknown person", 404)
})
mocker.delete("/bcu/persons/:id", request => {
const id = request.params.id
persons = persons.filter(person => person.id !== id)
})
mocker.put("/api/persons/:id", request => {
const id = request.params.id
const fields = JSON.parse(request.body)
const person = findPerson(id)
if (!person) return mocker.makeResponse("Unknown person", 404)
for (const n in fields) {
if (person.hasOwnProperty(n)) person[n] = fields[n]
}
return person
})
mocker.post("/api/persons/", request => {
const newPerson = JSON.parse(request.body)
const id = Number(persons[persons.length - 1].id) + 1
newPerson.id = String(id)
persons.push(newPerson)
return { id }
})
mocker.enable()
FAQs
mocker for fetch requests in browser
The npm package fetch-mocker receives a total of 0 weekly downloads. As such, fetch-mocker popularity was classified as not popular.
We found that fetch-mocker 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's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.