0.0.3 • Published 1 year ago

webpack-mock-api v0.0.3

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

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.

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago