<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Maesi</title>
    <description>The latest articles on DEV Community by Maesi (@marcel_lehmann_31109127df).</description>
    <link>https://dev.to/marcel_lehmann_31109127df</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3119590%2F017be7ab-fffe-4fa3-8abc-6250b5c962e9.png</url>
      <title>DEV Community: Maesi</title>
      <link>https://dev.to/marcel_lehmann_31109127df</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/marcel_lehmann_31109127df"/>
    <language>en</language>
    <item>
      <title>Ensuring Compliance with the HTTP API Contract Using Mokapi for Request Forwarding and Validation</title>
      <dc:creator>Maesi</dc:creator>
      <pubDate>Tue, 09 Dec 2025 10:00:00 +0000</pubDate>
      <link>https://dev.to/marcel_lehmann_31109127df/ensuring-compliance-with-the-http-api-contract-using-mokapi-for-request-forwarding-and-validation-1830</link>
      <guid>https://dev.to/marcel_lehmann_31109127df/ensuring-compliance-with-the-http-api-contract-using-mokapi-for-request-forwarding-and-validation-1830</guid>
      <description>&lt;p&gt;In modern distributed systems, APIs are everywhere — frontend-to-backend, backend-to-backend, microservices communicating internally, mobile apps, test automation tools, and more. Each interaction relies on a shared API contract, often expressed through an OpenAPI specification. Even small deviations can introduce bugs, break integrations, or slow down development.&lt;/p&gt;

&lt;p&gt;By placing Mokapi between a client and a backend, you can ensure that every &lt;strong&gt;request and response adheres to your OpenAPI specification&lt;/strong&gt;. With a few lines of JavaScript, Mokapi can forward requests to your backend while validating both sides of the interaction. This provides a powerful way to enforce API correctness — whether the client is a browser, Playwright tests, your mobile app, or even another backend service.&lt;/p&gt;

&lt;p&gt;In this article, I explore how Mokapi can act as a &lt;strong&gt;contract-enforcing validation layer&lt;/strong&gt; and why this approach benefits frontend developers, backend teams, QA engineers, and platform engineers alike.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faev78f81ltu6pk7akpgg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faev78f81ltu6pk7akpgg.png" alt=" " width="800" height="344"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to Use Mokapi for API Validation with Request Forwarding?
&lt;/h2&gt;

&lt;p&gt;Mokapi cannot only be used for mocking APIs, but it can also sit between any &lt;br&gt;
consumer and a backend service to validate real traffic. Using a small&lt;br&gt;
JavaScript script, Mokapi can forward requests to your backend and&lt;br&gt;
validates both requests and responses.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;on&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;mokapi&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;fetch&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;mokapi/http&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="cm"&gt;/**
 * This script demonstrates how to forward incoming HTTP requests
 * to a real backend while letting Mokapi validate responses according
 * to your OpenAPI spec.
 *
 * The script listens to all HTTP requests and forwards them based
 * on the `request.api` field. Responses from the backend are
 * validated when possible, and any errors are reported back to
 * the client.
 */&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nf"&gt;function &lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="cm"&gt;/**
     * Register a global HTTP event handler.
     * This function is called for every incoming request.
     */&lt;/span&gt;
    &lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;http&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

        &lt;span class="c1"&gt;// Determine the backend URL to forward this request to&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;getForwardUrl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="c1"&gt;// If no URL could be determined, return an error immediately&lt;/span&gt;
        &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;statusCode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Failed to forward request: unknown backend&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt; 

        &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="c1"&gt;// Forward the request to the backend&lt;/span&gt;
            &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;method&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="na"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;header&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="na"&gt;timeout&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;30s&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
            &lt;span class="p"&gt;});&lt;/span&gt;

            &lt;span class="c1"&gt;// Copy status code and headers from the backend response&lt;/span&gt;
            &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;statusCode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;statusCode&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;headers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;headers&lt;/span&gt;

            &lt;span class="c1"&gt;// Check the content type to decide whether to validate the response&lt;/span&gt;
            &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;contentType&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Content-Type&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]?.[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

            &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;contentType&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;application/json&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="c1"&gt;// Mokapi can validate JSON responses automatically&lt;/span&gt;
                &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="c1"&gt;// For other content types, skip validation&lt;/span&gt;
                &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="c1"&gt;// Handle any errors that occur while forwarding&lt;/span&gt;
            &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;statusCode&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;

    &lt;span class="cm"&gt;/**
     * Maps the incoming request to a backend URL based on the API name
     * defined in the OpenAPI specification (`info.title`).
     * @see https://mokapi.io/docs/javascript-api/mokapi/eventhandler/httprequest
     *
     * @param request - the incoming Mokapi HTTP request
     * @returns the full URL to forward the request to, or undefined
     */&lt;/span&gt;
    &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getForwardUrl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;HttpRequest&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;switch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;api&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;backend-1&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;`https://backend1.example.com&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;?&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;backend-2&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s2"&gt;`https://backend1.example.com&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;path&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;?&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="nl"&gt;default&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;undefined&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For each interaction, Mokapi performs four important steps:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Validates incoming requests
&lt;/h3&gt;

&lt;p&gt;Mokapi checks every incoming request against your OpenAPI specification:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;HTTP method&lt;/li&gt;
&lt;li&gt;URL &amp;amp; parameters&lt;/li&gt;
&lt;li&gt;headers&lt;/li&gt;
&lt;li&gt;request body&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If the client sends anything invalid, Mokapi blocks it and returns a clear &lt;br&gt;
validation error.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Forwards valid requests to your backend
&lt;/h3&gt;

&lt;p&gt;If the request is valid, Mokapi forwards it unchanged to the backend using JavaScript.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;No changes are required in your backend.&lt;/li&gt;
&lt;li&gt;No additional infrastructure is necessary.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. Validates backend responses
&lt;/h3&gt;

&lt;p&gt;Once the backend responds, Mokapi validates the response against the OpenAPI specification:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;status codes &lt;/li&gt;
&lt;li&gt;headers &lt;/li&gt;
&lt;li&gt;response body&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If something doesn't match the contract, Mokapi blocks it and sends a validation error back to the client.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Return the validated response to the client
&lt;/h3&gt;

&lt;p&gt;Only responses that pass validation reach the client, guaranteeing contract fidelity end-to-end.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where You Can Use Mokapi for Request Forwarding and Validation
&lt;/h2&gt;

&lt;p&gt;Mokapi’s forwarding and validation capabilities make it useful far beyond local development or Playwright scripting.&lt;/p&gt;

&lt;h3&gt;
  
  
  Between Frontend and Backend
&lt;/h3&gt;

&lt;p&gt;Placing Mokapi between your frontend and backend ensures:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;automatic request and response validation &lt;/li&gt;
&lt;li&gt;immediate detection of breaking changes &lt;/li&gt;
&lt;li&gt;backend and API specification evolve together&lt;/li&gt;
&lt;li&gt;fewer “why is the frontend broken?” debugging loops&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Frontend developers can experiment with confidence, knowing the backend&lt;br&gt;
cannot silently diverge from the published contract.&lt;/p&gt;

&lt;h3&gt;
  
  
  Between Backend Services (Service-to-Service)
&lt;/h3&gt;

&lt;p&gt;In microservice architectures, API drift between services is a frequent cause of instability.&lt;br&gt;
Routing service-to-service traffic through Mokapi gives you:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;strict contract enforcement between services &lt;/li&gt;
&lt;li&gt;early detection of incompatible changes &lt;/li&gt;
&lt;li&gt;stable integrations even as teams evolve independently &lt;/li&gt;
&lt;li&gt;clear validation errors during development and CI&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Mokapi becomes a lightweight, spec-driven contract guardian across your backend ecosystem.&lt;/p&gt;

&lt;h3&gt;
  
  
  In Automated Testing (e.g., Playwright)
&lt;/h3&gt;

&lt;p&gt;This is one of the most powerful setups.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Playwright → Mokapi → Backend
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Benefits:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;CI fails immediately when the backend breaks the API contract &lt;/li&gt;
&lt;li&gt;tests interact with the real backend, not mocks&lt;/li&gt;
&lt;li&gt;validation errors are clear and actionable &lt;/li&gt;
&lt;li&gt;tests remain simpler — no need to validate everything in Playwright&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Your tests are guaranteed to hit a backend that actually matches the API contract.&lt;/p&gt;

&lt;h3&gt;
  
  
  In Kubernetes Test Environments
&lt;/h3&gt;

&lt;p&gt;Mokapi can also be used in temporary or preview environments to ensure contract validation across the entire cluster.&lt;/p&gt;

&lt;p&gt;In Kubernetes, Mokapi can be deployed as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a sidecar container&lt;/li&gt;
&lt;li&gt;a standalone validation layer in front of backend services&lt;/li&gt;
&lt;li&gt;a temporary component inside preview environments&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This brings:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;consistent contract validation for all cluster traffic&lt;/li&gt;
&lt;li&gt;early detection of breaking API changes before staging&lt;/li&gt;
&lt;li&gt;contract enforcement without modifying backend services&lt;/li&gt;
&lt;li&gt;transparent operation — apps talk to Mokapi, Mokapi talks to the backend&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can integrate Mokapi into Helm charts, GitOps workflows, or test namespaces.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Teams Benefit from Using Mokapi Between Client and Backend
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Automatic Contract Enforcement
&lt;/h3&gt;

&lt;p&gt;Every interaction is validated against your OpenAPI specification. Your backend can no longer quietly drift from the contract.&lt;/p&gt;

&lt;h3&gt;
  
  
  Immediate Detection of Breaking Changes
&lt;/h3&gt;

&lt;p&gt;Issues are caught early, not just in staging or production, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;renamed or missing fields&lt;/li&gt;
&lt;li&gt;wrong or inconsistent formats&lt;/li&gt;
&lt;li&gt;unexpected status codes&lt;/li&gt;
&lt;li&gt;mismatched data types&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  More Reliable Frontend Development
&lt;/h3&gt;

&lt;p&gt;Frontend teams get:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;consistent, validated API responses&lt;/li&gt;
&lt;li&gt;fewer sudden breaking changes&lt;/li&gt;
&lt;li&gt;a smoother development workflow&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This reduces context-switching and debugging time.&lt;/p&gt;

&lt;h3&gt;
  
  
  Better Collaboration Between Teams
&lt;/h3&gt;

&lt;p&gt;With Mokapi validating both sides:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;backend developers instantly see when they violate the contract&lt;/li&gt;
&lt;li&gt;frontend engineers get stable, predictable APIs&lt;/li&gt;
&lt;li&gt;QA gets reliable test environments&lt;/li&gt;
&lt;li&gt;platform engineers reduce risk during deployments&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Mokapi becomes a shared API contract watchdog across the organization.&lt;/p&gt;

&lt;h3&gt;
  
  
  Smooth Transition from Mocks to Real Systems
&lt;/h3&gt;

&lt;p&gt;Teams often start with mocked endpoints in early development. Later, they can simply begin forwarding requests to the&lt;br&gt;
real backend—while keeping validation in place.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Using Mokapi between frontend and backend, between backend services, or inside Kubernetes environments provides:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;strong contract enforcement&lt;/li&gt;
&lt;li&gt;automatic validation for every interaction&lt;/li&gt;
&lt;li&gt;early detection of breaking changes&lt;/li&gt;
&lt;li&gt;stable multi-team integration&lt;/li&gt;
&lt;li&gt;more reliable CI pipelines&lt;/li&gt;
&lt;li&gt;a smooth path from mocking to real backend validation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Mokapi ensures your API stays aligned with its specification, no matter how quickly your system evolves.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Mokapi becomes your always-on API contract guardian — lightweight, transparent, and spec-driven.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;This article is also available on my website: &lt;a href="https://mokapi.io/docs/resources/blogs/ensuring-api-contract-compliance-with-mokapi" rel="noopener noreferrer"&gt;Mokapi.io&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>mockapi</category>
      <category>openapi</category>
      <category>proxy</category>
    </item>
    <item>
      <title>Testing Kafka Workflows Without Kafka — With Playwright &amp; Mokapi</title>
      <dc:creator>Maesi</dc:creator>
      <pubDate>Wed, 20 Aug 2025 20:30:38 +0000</pubDate>
      <link>https://dev.to/marcel_lehmann_31109127df/testing-kafka-workflows-without-kafka-with-playwright-mokapi-29l1</link>
      <guid>https://dev.to/marcel_lehmann_31109127df/testing-kafka-workflows-without-kafka-with-playwright-mokapi-29l1</guid>
      <description>&lt;p&gt;Event-driven systems are powerful — but testing them can feel heavy.  &lt;/p&gt;

&lt;p&gt;Spinning up a Kafka cluster, checking if specifications are met, producing test input, and reading results from topics… it adds a lot of overhead, especially in CI pipelines.  &lt;/p&gt;

&lt;p&gt;What if you could test Kafka workflows &lt;strong&gt;without running a Kafka cluste&lt;/strong&gt;r?&lt;br&gt;&lt;br&gt;
That’s exactly what &lt;a href="https://mokapi.io" rel="noopener noreferrer"&gt;Mokapi&lt;/a&gt; enables.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why This Matters
&lt;/h2&gt;

&lt;p&gt;Testing event-driven workflows usually means juggling infrastructure:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Running a local or containerized Kafka broker&lt;/li&gt;
&lt;li&gt;Making sure topics and schemas match the spec&lt;/li&gt;
&lt;li&gt;Setting up test producers and consumers&lt;/li&gt;
&lt;li&gt;Verifying results at the topic level&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For end-to-end workflow tests, this slows you down. With Mokapi, you can skip the cluster and use a &lt;strong&gt;Kafka-like REST API&lt;/strong&gt; for producing and consuming records — perfectly aligned with your AsyncAPI specs.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Testing Scenario
&lt;/h2&gt;

&lt;p&gt;Let’s walk through a realistic workflow.&lt;br&gt;&lt;br&gt;
In our system:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A foreign system sends a command to &lt;code&gt;document.send-command&lt;/code&gt; (Kafka topic).
&lt;/li&gt;
&lt;li&gt;Our backend consumes this command, simulates sending the document, and then publishes a result to &lt;code&gt;document.send-event&lt;/code&gt;.
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here’s how we test this with &lt;strong&gt;Playwright + Mokapi&lt;/strong&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Produce input&lt;/strong&gt; — Playwright sends a Kafka record into &lt;code&gt;document.send-command&lt;/code&gt; using Mokapi’s REST API.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Backend processes the command&lt;/strong&gt; — our Node.js backend consumes the command and publishes the outcome into &lt;code&gt;document.send-event&lt;/code&gt;.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Verify the result&lt;/strong&gt; — Playwright retrieves the new record from &lt;code&gt;document.send-event&lt;/code&gt; via Mokapi’s REST API and checks the &lt;code&gt;documentId&lt;/code&gt; and &lt;code&gt;status&lt;/code&gt;.
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This gives us &lt;strong&gt;full end-to-end confidence&lt;/strong&gt; without running Kafka.&lt;/p&gt;




&lt;h2&gt;
  
  
  Example Setup
&lt;/h2&gt;

&lt;p&gt;👉 The full example project is available here: &lt;a href="https://github.com/marle3003/mokapi-kafka-workflow" rel="noopener noreferrer"&gt;mokapi-kafka-workflow&lt;/a&gt;.  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Backend&lt;/strong&gt;: Node.js consumer + producer
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Mokapi&lt;/strong&gt;: mocks the Kafka cluster using AsyncAPI
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Playwright&lt;/strong&gt;: drives the test by producing and verifying messages
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Playwright doesn’t open a browser UI in this case — it’s simply used as a testing framework with clean assertions and easy integration into CI.&lt;/p&gt;




&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This example shows how to build an &lt;strong&gt;end-to-end Kafka workflow test&lt;/strong&gt; with Playwright and Mokapi:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;✅ Simple setup — no Kafka broker required
&lt;/li&gt;
&lt;li&gt;✅ Produce and consume messages via REST
&lt;/li&gt;
&lt;li&gt;✅ Works seamlessly in CI/CD pipelines
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And this pattern scales: you can expand it to multiple backends and topics while keeping tests easy to write and maintain.  &lt;/p&gt;

&lt;p&gt;With Mokapi, testing Kafka workflows becomes &lt;strong&gt;lightweight, reliable, and spec-driven&lt;/strong&gt;.  &lt;/p&gt;

&lt;p&gt;🔗 Read the full tutorial on &lt;a href="https://mokapi.io/docs/resources/blogs/testing-kafka-workflows-with-playwright-and-mokapi" rel="noopener noreferrer"&gt;mokapi.io&lt;/a&gt;&lt;/p&gt;

</description>
      <category>mockapi</category>
      <category>mock</category>
      <category>api</category>
    </item>
    <item>
      <title>Acceptance Testing with Mokapi: Focus on What Matters</title>
      <dc:creator>Maesi</dc:creator>
      <pubDate>Tue, 08 Jul 2025 11:24:48 +0000</pubDate>
      <link>https://dev.to/marcel_lehmann_31109127df/acceptance-testing-with-mokapi-focus-on-what-matters-4jd6</link>
      <guid>https://dev.to/marcel_lehmann_31109127df/acceptance-testing-with-mokapi-focus-on-what-matters-4jd6</guid>
      <description>&lt;p&gt;In today’s fast-paced development cycles, it’s crucial to ensure your software meets real user expectations. While unit tests validate internal code, acceptance testing answers the bigger question: Does the system behave as users expect? This post explores the value of acceptance tests and how &lt;a href="https://mokapi.io" rel="noopener noreferrer"&gt;Mokapi&lt;/a&gt; supports it by simulating APIs, validating specifications, and enabling robust, realistic test cases.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Acceptance Testing
&lt;/h2&gt;

&lt;p&gt;Software testing is not merely a box to check—it is a fundamental process to answer one critical question: Is our software releasable?&lt;/p&gt;

&lt;p&gt;Among the various levels of testing, acceptance testing offers the most direct insight into whether the software meets business and user expectations. It bridges the gap between the world of users and the inner workings of the code by turning expectations into precise, executable checks on system behavior.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Nature of Acceptance Tests
&lt;/h3&gt;

&lt;p&gt;At its core, an acceptance test is an executable specification of how a system should behave, written from a user’s perspective. It is not concerned with how the system is implemented, but with what it does—its behavior and its outcomes.&lt;/p&gt;

&lt;p&gt;While unit tests focus on individual components, acceptance tests focus on the system's intent. They clarify what should happen when a user interacts with the software under certain conditions.&lt;/p&gt;

&lt;p&gt;When we get the level of abstraction right, acceptance tests become clear, precise, and maintainable. They reflect scenarios that matter to users, expressed in a way that is both easy to read and easy to execute. They serve as living documentation that evolves with the system and its requirements.&lt;/p&gt;

&lt;h3&gt;
  
  
  Solving Ambiguity and Ensuring Reproducibility
&lt;/h3&gt;

&lt;p&gt;One of the most challenging aspects of software development is not writing code—it is understanding the problem clearly and expressing it precisely. Programs are, after all, specifications of what we want the system to do. But unlike natural languages, which are rich in context and ambiguity, software requires unambiguous clarity.&lt;/p&gt;

&lt;p&gt;This is where acceptance testing shines.&lt;/p&gt;

&lt;p&gt;By expressing requirements in an executable form, acceptance tests remove ambiguity. They define exactly what needs to happen. Rather than relying on vague documentation or human interpretation, developers, testers, and stakeholders can rely on concrete, shared understanding. The tests describe behavior, not implementation details, which makes them robust to changes in how the system is built, as long as it continues to behave as expected.&lt;/p&gt;

&lt;p&gt;Moreover, acceptance tests are reproducible. They can be run automatically, as often as needed, to ensure the software continues to meet its defined expectations. This reproducibility is crucial for modern CI pipelines, where tests are run continuously to catch regressions early&lt;/p&gt;

&lt;h3&gt;
  
  
  A Contract of Trust
&lt;/h3&gt;

&lt;p&gt;In a collaborative development environment, acceptance tests serve as a contract between the business and the development team. When everyone agrees on the specifications encoded in the tests, there is no room for misinterpretation. The business gets what it asked for, and developers have a reliable guide to follow.&lt;/p&gt;

&lt;p&gt;This contract is especially important in agile and iterative processes, where requirements evolve and features are delivered incrementally. With acceptance tests in place, the team always has a clear picture of what "done" means.&lt;/p&gt;

&lt;h3&gt;
  
  
  Making Software Releasable
&lt;/h3&gt;

&lt;p&gt;Acceptance testing answers a key question: Is the software ready to release? It gives us confidence that the features meet user needs and work correctly. It also checks that we built what was actually requested. Most importantly, it does this in a way that’s automated, repeatable, and reliable.&lt;/p&gt;

&lt;p&gt;By aligning development with user intent, removing ambiguity, and validating results, acceptance testing becomes an essential practice—not just for verifying software, but for clearly understanding and specifying it in the first place.&lt;/p&gt;

&lt;h3&gt;
  
  
  The problem with acceptance testing and 3rd party APIs
&lt;/h3&gt;

&lt;p&gt;Unstable – External APIs can fail randomly, whether due to bugs or release workflows.&lt;br&gt;
No test environment – Many APIs don’t offer a dedicated environment for testing.&lt;br&gt;
Uncontrollable state – It’s often impossible to set up the external system in the desired state for your tests.&lt;/p&gt;

&lt;p&gt;These limitations can make acceptance testing brittle and unreliable—unless you can simulate the external system reliably.&lt;/p&gt;
&lt;h2&gt;
  
  
  How Mokapi Supports Acceptance Testing
&lt;/h2&gt;

&lt;p&gt;That’s where &lt;a href="https://mokapi.io" rel="noopener noreferrer"&gt;Mokapi&lt;/a&gt; comes in. It lets you simulate realistic API behavior in a way that’s fast, accurate, and under your full control.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm8skadwhq08g0t994186.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm8skadwhq08g0t994186.png" alt=" " width="800" height="429"&gt;&lt;/a&gt;&lt;br&gt;
Acceptance testing becomes significantly more effective with the right tools—especially in complex environments with multiple APIs, microservices, and evolving interfaces. Mokapi was developed to address precisely these challenges. It provides a powerful, flexible, and specification-oriented approach to API simulation, enabling high-quality acceptance testing in a wide variety of scenarios.&lt;/p&gt;
&lt;h3&gt;
  
  
  Acceptance Testing Across Boundaries
&lt;/h3&gt;

&lt;p&gt;Mokapi makes acceptance testing easier across flexible system boundaries—whether you're focusing on a single microservice or validating your entire architecture—by mocking the APIs they depend on.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxluy255s1g29y21ciutg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxluy255s1g29y21ciutg.png" alt=" " width="800" height="429"&gt;&lt;/a&gt;&lt;br&gt;
Powerful Flexibility for Real-World Scenarios&lt;br&gt;
With Mokapi, you're not limited to ideal cases. The JavaScript-based mock handlers enable the simulation of a wide variety of real-world scenarios, including negative tests, edge cases, and error conditions—all essential for developing robust software. You can programmatically control responses based on request data, headers, or business logic, giving you precise control over your mock's behavior during a test.&lt;/p&gt;

&lt;p&gt;This flexibility helps you answer not only the question "Does it work?" but also "Does it work when third-party systems don't."&lt;/p&gt;
&lt;h3&gt;
  
  
  Specification-Driven Confidence
&lt;/h3&gt;

&lt;p&gt;One of Mokapi's key strengths is its close alignment with API specifications. Mocks are continuously validated against OpenAPI or AsyncAPI definitions, ensuring they accurately reflect the APIs being simulated. This becomes especially valuable as APIs evolve.&lt;/p&gt;

&lt;p&gt;When a provider releases a new API version, it can be easily updated in Mokapi. If mock data or API calls no longer conform to the updated specification, Mokapi returns errors that can be caught through acceptance testing. This supports automated API version updates and acts as an early warning system for potential production issues.&lt;/p&gt;
&lt;h3&gt;
  
  
  Smart Mock Customization with Patch Mechanism
&lt;/h3&gt;

&lt;p&gt;Mokapi supports a patching mechanism for both API specifications and mock data. Patching the specification helps you adopt new API versions more easily while keeping track of your own modifications to the original spec. Patching mock data, on the other hand, allows you to avoid over-mocking—keeping your tests stable and focused, so changes are only required when they’re truly relevant.&lt;/p&gt;

&lt;p&gt;Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;on&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;patch&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;mokapi&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;fake&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;mokapi/faker&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Open the OpenAPI pet store specification, resolving all $ref references&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;api&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;pet-store-api.yaml&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;as&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;resolved&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

    &lt;span class="c1"&gt;// Generate a random pet object based on the OpenAPI schema&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;pet&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;fake&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;api&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;components&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;schemas&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;pet&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;http&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Use the generated pet but override the name to 'Odie'&lt;/span&gt;
        &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;patch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;pet&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Odie&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

        &lt;span class="c1"&gt;// Alternatively, patch Mokapi's autogenerated response and just set the name&lt;/span&gt;
        &lt;span class="c1"&gt;// response.data = patch(response.data, { name: 'Odie' });&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This example demonstrates how you can generate valid mock data that conforms to the API specification and then customize only the parts relevant to your test—such as setting a specific pet name—without redefining the entire response structure.&lt;/p&gt;

&lt;h3&gt;
  
  
  Making Acceptance Testing Sustainable
&lt;/h3&gt;

&lt;p&gt;By combining flexible mocks, specification validation, and a smart patching mechanism, Mokapi makes acceptance testing more resilient, more focused, and easier to maintain. It helps your team test confidently—whether you're building a new feature in isolation, validating complex integrations, or preparing for a production release.&lt;/p&gt;

&lt;p&gt;Mokapi doesn’t just enable acceptance testing—it makes it practical, maintainable, and deeply aligned with your evolving system and its requirements.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ready to get started?
&lt;/h2&gt;

&lt;p&gt;Learn how to set up acceptance tests with Mokapi in your CI/CD pipeline:&lt;/p&gt;

&lt;p&gt;👉 &lt;a href="https://mokapi.io/docs/resources/tutorials/running-mokapi-in-a-ci-cd-pipeline" rel="noopener noreferrer"&gt;Running Mokapi in a CI/CD Pipeline&lt;/a&gt;&lt;br&gt;
👉 &lt;a href="https://mokapi.io/docs/guides/welcome" rel="noopener noreferrer"&gt;Mokapi Documentation&lt;/a&gt;&lt;/p&gt;

</description>
      <category>testing</category>
      <category>mocking</category>
      <category>api</category>
    </item>
  </channel>
</rss>
