JSON API Greasing with Membrane

What is API Greasing? API greasing is a technique used to introduce controlled randomness in API responses or requests, ensuring that clients can handle unexpected variations in data structures. This helps improve system resilience and robustness.

In Membrane, you can add the grease element to requests or responses to grease specific types of data. For example, using jsonGrease to add noise to a JSON request. By setting the ratio to 10%, approximately 10 out of every 100 requests will be greased. In this example we set the ratio to 1.0 (default), this will force every request to be greased.

Configuration

The following configuration applies JSON greasing to API responses.

<api port="2000">
<request>
<greaser>
<greaseJson ratio="1.0" shuffleFields="true" additionalProperties="true" />
</greaser>
</request>
<target url="http://localhost:2001" />
</api>
<api port="2000">
    <request>
        <greaser>
            <greaseJson ratio="1.0" shuffleFields="true" additionalProperties="true" />
        </greaser>
    </request>
    <target url="http://localhost:2001" />
</api>

Understanding greaseJson Attributes

  • ratio: Defines the percentage of requests that should be greased (e.g., 0.1 for 10%).
  • shuffleFields: If set to true, JSON fields are reordered.
  • additionalProperties: Adds extra random fields to JSON responses.

Resources

greaseJsonExample