---
title: Creating Expectations
description: Define request matchers and response actions in MockServer using the Java, JavaScript, Python, Ruby, Go, .NET, Rust, or PHP client, REST API, or JSON files.
layout: page
pageOrder: 1
section: 'Creating Mocks'
subsection: true
sitemap:
priority: 0.8
changefreq: 'monthly'
lastmod: 2026-06-10T00:00:00+00:00
---
This page contains over 100 detailed code examples covering every matcher and response action across 8 client languages — Java, JavaScript, Python, Ruby, Go, .NET, Rust, and PHP — plus the equivalent REST API / JSON. Use the accordion tabs in each example to switch to your language.
{% include_subpage _includes/creating_expectations.html %}
Next Steps
- Verify Requests — assert that your code under test sent the requests you expected, with the right headers, body, and call count
- Troubleshoot Matching — work out why a request did not match the expectation you configured
- Response Templates — build dynamic responses from the incoming request using Velocity, Mustache, or JavaScript templates
- Stateful Scenarios — model multi-step, stateful API behaviour with sequential or cycling responses and state transitions
- Using OpenAPI — generate expectations automatically from an OpenAPI / Swagger specification
- Before & After Actions — fire extra HTTP webhooks or callbacks before or after an expectation's response to mirror, shadow, fan-out, or gate live traffic
- Clearing & Resetting — remove expectations and recorded requests between tests to keep state isolated
- Persisting Expectations — save and reload expectations so they survive restarts