ui-http-mock
v1.0.1
Published
Mocking http calls for UI development
Maintainers
Readme
ui-http-mock
A lightweight CLI tool for mocking HTTP API endpoints during UI development. Define JSON response files in a simple directory structure and spin up a mock server instantly — no backend required.
Installation
Global — run ui-http-mock from anywhere:
npm install -g ui-http-mockLocal (recommended) — install as a dev dependency in your project:
npm install --save-dev ui-http-mockThen add a script to your package.json:
{
"scripts": {
"mock": "ui-http-mock"
}
}Run it with:
npm run mockNo install — run once via npx:
npx ui-http-mockUsage
ui-http-mock [options]Options
| Option | Type | Default | Description |
|---|---|---|---|
| --port | number | 8080 | Port to listen on |
| --mock-dir | path | mocks | Directory containing mock files |
| --prefix | string | (none) | URL prefix for all routes |
| --delay | number | 0 | Max random response delay in ms |
| --help | — | — | Show help message |
Examples
ui-http-mock # Start on port 8080, load ./mocks
ui-http-mock --port 3000 # Start on port 3000
ui-http-mock --mock-dir ./data # Load mocks from ./data
ui-http-mock --prefix /api # All routes prefixed with /api
ui-http-mock --delay 500 # Add up to 500ms random delayMock File Structure
Organize mock files by route path and HTTP method. Each file is named after the HTTP method (lowercase) and contains the JSON response body.
mocks/
├── users/
│ ├── get.json # GET /users
│ ├── post.json # POST /users
│ └── [id]/
│ ├── get.json # GET /users/:id
│ └── patch.json # PATCH /users/:id
└── posts/
└── get.json # GET /postsDynamic Routes
Use [paramName] folder names to match dynamic URL segments:
mocks/
└── products/
└── [id]/
├── get.json # matches GET /products/1, /products/abc, etc.
└── delete.json # matches DELETE /products/1, etc.Example Mock File
mocks/users/get.json:
[
{ "id": "1", "firstName": "John", "lastName": "Doe", "email": "[email protected]" },
{ "id": "2", "firstName": "Jane", "lastName": "Smith", "email": "[email protected]" }
]Supported HTTP Methods
GET POST PUT DELETE PATCH
License
ISC
