webpack-mock-api

0.0.3 • Public • Published

webpack-mock-api

npm version

Easily mock apis with express, webpack-dev-server or webpack-dev-middleware.

Setup

Create a directory with stubbed api responses with a directory structure that mirrors your api.

For example:

If my app makes an api call to ./api/users, I would create a file at ./mocks/api/users.json with the response data from my network call.

Then install webpack-mock-api:

npm install -D webpack-mock-api

Express / webpack-dev-middleware

const app = require('express')();

mockApi.expressMockApi({
  app,
  apiRootDir: path.resolve(__dirname, 'mocks', 'api'),
  apiPrefix: '/api',
});

This will use the directories from ./mocks/api to create a mock api endpoint at ./api over the network.

So a request to ./api/users will return the file contents of ./mocks/api/users.json.

(Coming soon) webpack-dev-server

For now you need to use webpack-dev-middleware.

Package Sidebar

Install

npm i webpack-mock-api

Weekly Downloads

0

Version

0.0.3

License

MIT

Unpacked Size

5.75 kB

Total Files

5

Last publish

Collaborators

  • goldhand