Mock REST API

Mock REST API

The Mock REST API lets you create a "collection" — a named resource — and instantly get six fully functional CRUD endpoints backed by auto-generated realistic data. No backend, no database, no configuration.

Creating a collection

  1. Go to Mock API in the MockLab dashboard.
  2. Click New Collection and give it a name (e.g. products).
  3. MockLab generates a schema from the name and immediately creates sample records.
  4. Your endpoints are live instantly — no deployment step.

Endpoint format

Every collection exposes six REST endpoints at a public URL:

https://api.mocklab.dev/m/userId/resourceName

Replace userId with your account ID and resourceName with your collection name.

Method Path Action
GET /m/userId/products List all records (supports ?limit, ?offset, ?sort)
GET /m/userId/products/:id Get a single record by ID
POST /m/userId/products Create a new record
PUT /m/userId/products/:id Replace a record entirely
PATCH /m/userId/products/:id Update specific fields on a record
DELETE /m/userId/products/:id Delete a record

Example responses

GET /m/user123/products 200 OK
{
  "data": [
    {
      "id": "prod_4kX9z",
      "name": "Wireless Headphones Pro",
      "price": 79.99,
      "currency": "USD",
      "inStock": true,
      "category": "Electronics",
      "createdAt": "2024-11-03T14:22:00Z"
    },
    {
      "id": "prod_mR2qP",
      "name": "Ergonomic Standing Desk",
      "price": 449.00,
      "currency": "USD",
      "inStock": false,
      "category": "Furniture",
      "createdAt": "2024-11-01T09:15:00Z"
    }
  ],
  "total": 2,
  "limit": 20,
  "offset": 0
}
POST /m/user123/products 201 Created
// Request body
{
  "name": "USB-C Hub 7-in-1",
  "price": 39.99,
  "currency": "USD",
  "inStock": true
}

// Response
{
  "id": "prod_vX7kL",
  "name": "USB-C Hub 7-in-1",
  "price": 39.99,
  "currency": "USD",
  "inStock": true,
  "createdAt": "2024-11-05T11:00:00Z"
}

Query parameters

Parameter Description Example
?limit Number of records to return (default 20, max 100) ?limit=5
?offset Number of records to skip for pagination ?offset=20
?sort Field to sort by (prefix with - for descending) ?sort=-createdAt
?filter[*] Filter by field value ?filter[inStock]=true

Data persistence

Free Records reset daily at midnight UTC. Data created via POST/PUT/PATCH is not persisted across resets.
Pro Records persist indefinitely. Mutations (POST/PUT/PATCH/DELETE) are permanent until you manually reset or delete the collection.

CORS

All Mock API endpoints automatically include CORS headers, so you can call them directly from any browser-based frontend without proxy configuration:

Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, PUT, PATCH, DELETE, OPTIONS
Access-Control-Allow-Headers: Content-Type, Authorization