Fake Browser fetch ·
If you hate spinning up a web server everytime you are building a small pet project or demo project then this is for you 🎉
Features 💥
- fake GET/POST/PUT/DELETE fetch requests
- induce delay to any fetch request
- fake a 404 or error response
- generate response dynamically based on the request
How to use ❓
- Install it using npm
npm i --dev fake-browser-fetch
- Add it to your front-end project to fake a simple GET request
; ... ifprocessenvNODE_ENV === 'development' ; ... // will print { name: "Ameer Jhan" } after 3s ;
API
Faking a POST/PUT/DELETE request
;
Dynamic response based on request
; // this will print `ameer` ;
Faking a request to throw an error
const error = 'ETIMEOUT: the server timedout'; ; // this promise will get reject with `error`;
Inducing delay for all the requests
;
Customize 404 response
If fakeFetch could not find any fake config for a given request then it will return a default 404 response, you can also customize it as shown below
const _404Response = undefined status: 404 statusText: 'User defined 404 response' ; ;
Show your support by ⭐️ the repo
License
MIT © Ameer Jhan