Pseudo Fetch
Pseudo-fetch is a lightweight mock of the Fetch API. It does not try to be compliant to any standard, but instead to have a light and easy API for you to use.
Installation
npm install pseudo-fetch
Quickstart
Setting up a simple mock-server which responds to requests sent with fetch
is as easy as:
; const server = ; // Creates a server endpoint for you, and automatically overwrites window.fetch or global.fetch server ; // Or .send ; // Will log 'Hello world'
Accepting other methods than GET:
server ; // Alternatively// server// .route('/myroute', 'POST')// .send('Hello'); ; // Will print 404 ; // Will print 200
Sending JSON-data:
server ; ; // Will print // { // message: 'Hello world', // key: 'value' // }
Setting return status:
server status201 ; // Will log 201
Settings headers:
server ; // Or .respond ; // Will log '['plain/text']'
If you want to handle request/response data more thoroughly, you can supply a function accepting two arguments to .send or .respond.
server ; ;