FluxyAPIFluxyAPI
BlocksMiddleware

Body Validation

Validate the incoming request body payload against a defined schema.

Body Validation Middleware Block

The Body Validation Middleware Block ensures that the data sent by the client (the JSON payload) strictly matches the format and data types your endpoint expects.

Configuration

FieldRequiredDescription
SchemaA JSON schema or visual builder representation of the required fields.
Strict ModeIf enabled, requests containing extra fields not defined in the schema will be rejected.

Schema Definition

You can define:

  • Keys: The name of the JSON property.
  • Types: String, Number, Boolean, Array, or Object.
  • Required: Whether the key must be present.
  • Min/Max Length: Constraints for strings or arrays.

Behavior

When the endpoint runs, this block intercepts req.body. If the data does not conform to the defined rules, the block terminates the request and immediately sends an error response to the client. If Strip Unknown is true, the modified body is updated within the req.body context.

Errors & Responses

If validation fails, the block sends an HTTP response (default 400) to the client:

{
  "error": true,
  "message": "Field 'age' must be a number.",
  "code": "VALIDATION_TYPE_MISMATCH"
}

Common Error Keys: VALIDATION_BODY_INVALID, VALIDATION_MISSING_FIELD, VALIDATION_TYPE_MISMATCH, VALIDATION_MIN_LENGTH, VALIDATION_MAX_LENGTH, VALIDATION_REGEX_MISMATCH, VALIDATION_INTEGER_ONLY, VALIDATION_INVALID_DATE, VALIDATION_ENUM_MISMATCH, VALIDATION_INVALID_EMAIL, VALIDATION_MIN_VALUE, VALIDATION_MAX_VALUE, VALIDATION_MIN_ITEMS, VALIDATION_MAX_ITEMS, RUNTIME_ERROR

On this page