🚀 DAY 5 OF LAUNCH WEEK: Introducing Socket Firewall Enterprise.Learn more →
Socket
Book a DemoInstallSign in
Socket

@mocks-rs/mocks

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mocks-rs/mocks

Mock REST APIs from JSON with zero coding within seconds.

latest
Source
npmnpm
Version
1.0.9
Version published
Maintainers
1
Created
Source

mocks

Mock REST APIs from JSON with zero coding within seconds.

npm version codecov Ask DeepWiki License

Complete Documentation - For detailed usage, advanced features, and examples.

Install

npm install -g @mocks-rs/mocks

Or use without installing:

npx @mocks-rs/mocks --help

Quick Start

1. Initialize a storage file

Create a JSON file using the init command:

npx @mocks-rs/mocks init storage.json

Or if installed globally:

mocks init storage.json

This creates a storage.json file with sample data. Use the --empty option to create an empty structure:

npx @mocks-rs/mocks init --empty storage.json

Or if installed globally:

mocks init --empty storage.json

2. Run a REST API server

Start the mock server using your JSON file:

npx @mocks-rs/mocks run storage.json

Or if installed globally:

mocks run storage.json

Example JSON structure:

{
  "posts": [
    { "id": "01J7BAKH37HPG116ZRRFKHBDGB", "title": "first post", "views": 100 },
    { "id": "01J7BAKH37GE8B688PT4RC7TP4", "title": "second post", "views": 10 }
  ],
  "profile": { "id": "01J7BAQE1GMD78FN3J0FJCNS8T", "name": "mocks" }
}

3. Use your mock API

This automatically creates REST endpoints:

# List all posts
curl http://localhost:3000/posts

# Get a specific post
curl http://localhost:3000/posts/01J7BAKH37HPG116ZRRFKHBDGB

# Get profile (singleton resource)
curl http://localhost:3000/profile

# Create a new post
curl -X POST http://localhost:3000/posts \
  -H "Content-Type: application/json" \
  -d '{"title": "new post", "views": 0}'

# Health check
curl http://localhost:3000/_hc

Available Endpoints

For each resource in your JSON file, mocks automatically creates:

  • GET /{resource} - List all items
  • GET /{resource}/{id} - Get specific item
  • POST /{resource} - Create new item
  • PUT /{resource}/{id} - Replace entire item
  • PATCH /{resource}/{id} - Partial update
  • DELETE /{resource}/{id} - Delete item
  • GET /_hc - Health check (returns 204)

Documentation

For detailed information about advanced configuration, query parameters, filtering, and more features, visit the complete documentation.

Contributing

This project is open source. Visit the GitHub repository to contribute or report issues.

License

This project is licensed under the MIT license.

Keywords

mock

FAQs

Package last updated on 07 Sep 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts