Using Apinizer’s max message size policy, you are able to limit the maximum size of message bodies clients can send in their requests to your API. This can be used to reduce traffic, control data, or to protect your API against spam. To follow this tutorial, you should already have Apinizer installed and an API gateway defined.
For starters, go to your API’s gateway screen and click the “Add policy” button.
This will bring up a list of available policies. You’ll want to select “Max Message Size” from that list. Once you do, another dialog will open to ask you if you want to create this policy as a local or global policy. Local policies are kept with that gateway and can only be applied to that gateway. Global policies on the other hand are kept separately from a gateway, and can be used across many gateways. For our example, we’re going to create a local policy.
Defining the Policy
Once you select the “Local Policy” option, Apinizer will need you to determine the maximum message size. Any message who’s body size exceeds the maximum size will be rejected (Body size must be smaller or equal to max size).
Optionally, you can configure the error message that will be returned when a client is rejected. To do this, simply expand the section labeled “Error Message Customization” and enter your own error body in JSON format. You can also set the HTTP return code if you want to return a specific code.
After the max size is set, you can save the policy and redeploy the gateway. You should now have a working max message size for your API.
Apinizer’s documentation also features a page detailing the Max Message Size policy. You can find additional details about the policy at that page: