Skip to main content

Manage Data & State Variables

Beeceptor supports stateful mocks, enabling the simulation of persistent data across multiple HTTP requests. Unlike stateless mocks that return static or template-driven responses, stateful mocks are backed by a persistent datastore.

In a stateful scenario, the result of one API call (e.g., POST /users) can influence the outcome of a subsequent call (e.g., GET /users/123). This helps simulate real scenarios that are close to real API services.

info

Stateful mocking is supported across all Beeceptor plans, including the free tier. However, access to the UI-based visual data editors (below) is available only with paid plans.

Common Use Cases

Here are a few practical scenarios where stateful mocks shine:

  • Authentication Workflows Simulate user registration and login using POST /signup, POST /login, and GET /me by storing user credentials and session context.

  • Shopping Cart & Checkout Add items to cart by calling POST /cart, view cart using GET /cart, and remove items using DELETE /cart/:itemId. You can take this to next level by using user-id allowing mock server personalization for each logged in user.

  • Dynamic Form Wizards Save progress in multi-step forms (PUT /form/:step) and retrieve aggregated results (GET /form/summary).

CRUD Objects Editor

The CRUD Objects Editor offers a visual interface to manage mock data for your CRUD routes. It simplifies operations like creating, viewing, editing, and deleting data without writing code.

To access it, click "Manage Data" when editing a CRUD rule. You’ll see a dropdown of all your CRUD rules, and the current rule auto selected. Here you can,

  • Create an Object: Click “Create New” and enter a JSON object.
  • Edit an Object: Modify the object directly, except the identifier.
  • Delete: Remove individual records or clear all data for the selected route.
Importing new record for CRUD API route

Data State Editor

Beeceptor also supports advanced stateful operators within its response templating engine. These are:

  • step-counter: Increments a numeric value across calls (e.g., order numbers).
  • data-store: Key-value store for session-specific or global mock state.
  • list: Appends values to a list structure across API calls.

The Data State Editor lets you view and modify these stored values. This is helpful for debugging and checking if the values are correctly set when building stateful mocks.

Editing persisted list's items from State Editor UI

Note: While the keys themselves cannot be edited, their values can be changed or deleted. All the updates take effect immediately and reflect on the mock responses.