API
  • API Index
  • Batch API
  • Content Negotiation
  • Dynamic Paths
  • Hierarchy API
  • List API
  • Quick Reference
  • Time Series API
  • Views
    • Configuration
  • Overview
  • Application Configuration
  • Documentation Configuration
  • Spec Configuration
    • Features
  • API Testing
  • Asynchronous Processing
  • Cassandra Time-Series Engine
  • Cassandra Integration
  • Default Controller Customisation
  • Documentation
  • Geospatial Filtering
  • Model Documentation
  • PostgreSQL Integration
  • Excel Spreadsheet Format
    • Tutorials
  • Step-by-Step Guide
  • Archetype Setup
  • Logging
  • Prometheus
  • Sentry Logging
    • UI Customisation
  • UI Customisation
  • SASS Build Chain
  • Shared Layout
  • API Documentation
  • Model Documentation
  • Results
  • sapi-nt v current

    Request Validator Configuration

    In sapi-nt, request validators are conditions which are checked for each incoming request before it is accepted by the API. They can be configured uniquely for each endpoint, however multiple endpoints can share the same validator. Requests which don’t satisfy the validation rules will result in a 400 “Bad Request” response.

    Request validator specs are characterised by the following type values:

    Type Meaning
    validator.parameter.required A required parameter validator, which asserts that at least one value is given for each of a set of parameters.
    validator.parameter.pattern A parameter pattern validator, which asserts that all of the values given for a parameter match a certain Regex pattern.

    On endpoint specs, request validators can be referenced by their name value, or defined inline.

    Request Validator Types

    Required Parameter

    Required parameter validators, having a type value of validator.parameter.required, assert that at least one value is given for each of a set of parameters.

    The list of parameters is given by the params property of the spec.

    Example

    To define a validator which asserts that incoming requests must specify both label and title parameters, you can use the following spec:

    type: validator.parameter.required
    name: labelRequired
    params:
      - label
      - title
    

    Parameter Pattern

    Parameter pattern validators, having a type value of validator.parameter.pattern, assert that all of the values given for one or more parameters conform to a corresponding regular expression.

    The parameter-pattern pairs are given as key-value pairs on the nested params property of the spec. These values use standard regex syntax.

    Note

    If no value is given for a parameter that is validated by this validator, no assertion will be performed.

    Example

    To define a validator which asserts that the label parameter on incoming requests must have a value of foo or bar, and the title parameter must have a value of Baz or baz, you can use the following spec:

    type: validator.parameter.pattern
    name: labelFormat
    params:
      label: "foo|bar"
      title: "[Bb]az"