Package Exports
- servemocks
- servemocks/src/public-api.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (servemocks) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
servemocks
| Contributing | Changelog | Powered by diva-e |
|---|
Starts a webserver which provides a REST API derived from JSON, XML and other sample files located in a specified directory.
Consider the following directory structure:
mock-api/
├── image
│ └── logo.png
├── v1
│ ├── user
│ │ ├── 1.json
│ │ └── 2.json
│ ├── user.json
│ └── user.post.json
└── v2
├── health.json
└── sitemap.xmlServing directory mock-api with servemocks would create a webserver with the folllowing http endpoints:
- GET /image/logo.png
- GET /v1/user
- POST /v1/user
- GET /v1/user/1
- GET /v1/user/2
- GET /v2/health
- GET /v2/sitemap
Check the examples directory for more information about api conventions.
Getting Started
Install
# install as global package
npm install -g servemocks
# or project-local
npm install --save-dev servemocksUsage
servemocks <directory> [-p, --port=8080]Example:
servemocks examples/mock-api -p 5000Programmatic Usage
Servemocks is based on express and can be mounted as a submodule inside an existing app.
import { createServeMocksExpressApp } from 'servemocks';
const mainApp = express();
mainApp.use('/mock-api', createServeMocksExpressApp('examples/mock-api'))