Creating policies in code view

Discover the prerequisites for authoring policies in the code view.

IBM API Studio applies policies to control API behavior, security, and traffic management. The policies are defined individually in YAML format and are grouped in a policy sequence file to enforce multiple policies in a specific order.

Policy structure

Each policy is defined in a separate file, specifying the rules that it enforces. The kind attribute in the policy file identifies the policy type, such as Transport or Routing, determining its function within the API configuration.

A policy file includes the following fields:

  • kind. Specifies the asset type, such as URISchemes.
  • apiVersion. Defines the API schema version.
  • metadata. Specifies details like name, namespace, and version.
  • spec. Contains policy-specific configuration.

A sample for individual policy is as follows:

kind: URISchemes
apiVersion: api.ibm.com/v1
metadata:
  name: URI
  namespace: wm_policies
  version: '1.0'
  tags: []
  description: ''
spec:
  uriSchemes:
    - http
    - https

This URISchemes policy defines the allowed communication protocols for an API. It specifies that the API supports HTTP and HTTPS protocols, allowing requests over these transport methods.