--- title: CRUD Data Store description: Auto-generate a fully functional REST CRUD API over an in-memory JSON data store using a single PUT /mockserver/crud request, with no expectations required. shortTitle: CRUD Data Store layout: page pageOrder: 9.6 section: 'Mock Server' subsection: true sitemap: priority: 0.7 changefreq: 'monthly' lastmod: 2026-06-01T08:00:00+00:00 ---

The CRUD data store lets you stand up a complete REST API for a JSON resource with a single control-plane request. MockServer registers list, get, create, update, and delete endpoints automatically, backed by an in-memory store. No expectations need to be written by hand.

This is useful for tests that need a stateful resource API — for example, a `/users` service where test cases create, update, and delete records independently.

## Registering a CRUD resource

Send a PUT request to /mockserver/crud with a JSON body describing the resource. MockServer registers the endpoints immediately and returns a confirmation.

### Request fields

Field | Type | Required | Default | Description
--- | --- | --- | --- | ---
basePath | string | yes |  | Root path for the resource (e.g. /users). Must start with /, must not be /, and must not overlap /mockserver.
idField | string | no | id | Name of the JSON field used as the unique identifier in each item.
idStrategy | string enum | no | AUTO_INCREMENT | AUTO_INCREMENT — assigns sequential numeric ids starting at 1. UUID — assigns a random UUID string.
initialData | array of objects | no | null | Optional seed records to pre-populate the store. Each object must contain the id field; existing id values are preserved and the auto-increment counter is advanced past the highest numeric id found.

### Example request

    PUT /mockserver/crud HTTP/1.1
    Content-Type: application/json

    {
      "basePath": "/users",
      "idField": "id",
      "idStrategy": "AUTO_INCREMENT",
      "initialData": [
        {"id": 1, "name": "Alice", "email": "alice@example.com"},
        {"id": 2, "name": "Bob",   "email": "bob@example.com"}
      ]
    }

### Response (201 Created)

    {
      "basePath" : "/users",
      "idField" : "id",
      "idStrategy" : "AUTO_INCREMENT",
      "itemCount" : 2
    }

## Generated endpoints

After registration MockServer handles the following standard REST operations on the basePath. These are served by MockServer's own dispatcher before expectation matching, so they do not consume expectation slots.

Method | Path | Description | Success status
--- | --- | --- | ---
GET | {basePath} | Return all items as a JSON array, in insertion order. | 200
POST | {basePath} | Create a new item. MockServer assigns the id automatically (AUTO_INCREMENT or UUID) and returns the stored item. | 201
GET | {basePath}/{id} | Return a single item by id. Returns 404 if not found. | 200
PUT | {basePath}/{id} | Replace an item by id. The id field in the stored item is always set to the path id. Returns 404 if not found. | 200
PATCH | {basePath}/{id} | Partially update an item by id. Only the fields present in the request body are merged into the existing item (shallow merge). The id field cannot be changed via PATCH. Returns 404 if not found. | 200
DELETE | {basePath}/{id} | Delete an item by id. Returns 404 if not found. | 204

## Limits and lifecycle

- Each store holds up to 10,000 items by default. A POST that would exceed this limit returns 507 Insufficient Storage.
- The in-memory store is cleared when MockServer is reset (PUT /mockserver/reset). Re-register the CRUD resource after a reset if needed.
- Multiple CRUD resources can be registered at different base paths simultaneously.
- Registering the same basePath a second time replaces the existing handler and resets its store.

## Example usage

    # Register the resource
    curl -s -X PUT http://localhost:1080/mockserver/crud \
      -H 'Content-Type: application/json' \
      -d '{"basePath":"/users","idStrategy":"AUTO_INCREMENT"}'

    # Create a record
    curl -s -X POST http://localhost:1080/users \
      -H 'Content-Type: application/json' \
      -d '{"name":"Alice","email":"alice@example.com"}'
    # -> {"id":1,"name":"Alice","email":"alice@example.com"}

    # List all records
    curl -s http://localhost:1080/users
    # -> [{"id":1,"name":"Alice","email":"alice@example.com"}]

    # Get by id
    curl -s http://localhost:1080/users/1
    # -> {"id":1,"name":"Alice","email":"alice@example.com"}

    # Update (full replace)
    curl -s -X PUT http://localhost:1080/users/1 \
      -H 'Content-Type: application/json' \
      -d '{"name":"Alice Smith","email":"alice@example.com"}'

    # Partial update (PATCH - only change the email, keep the name)
    curl -s -X PATCH http://localhost:1080/users/1 \
      -H 'Content-Type: application/json' \
      -d '{"email":"alice.smith@example.com"}'
    # -> {"id":1,"name":"Alice Smith","email":"alice.smith@example.com"}

    # Delete
    curl -s -X DELETE http://localhost:1080/users/1