Set Media Type

Use the Set Media Typepolicy to define the content type. If the content type header is missing in a client request to an API, this policy adds the specified content type before the request is sent to the API.

Example of a Set Media Type policy.
kind: SetMediaType
apiVersion: api.webmethods.io/beta
metadata:
  name: setMediaType
  version: 1
  namespace: sample
spec: 
    defaultContentType: ${request.path}
    defaultAcceptHeader: ${request.httpMethod}
As part of the Set Media Type configuration, you can specify:
Type Description
kind SetMediaType. Denotes the asset type, which is a Set Media Type policy.
apiVersion Denotes the version of the API in use.
metadata Denotes the metadata or details of the asset type.
It covers this metadata:
  • name. Name of the policy.
  • version. Version of the policy.
  • namespace. Namespace identifier for the policy.
spec spec. Specifies the various policy properties that you can configure for the policy.
You can configure the following policy properties:
  • Set the default content type in the code view by using defaultContentType, or in the form view, under Default content type, which is an optional field.

    This field specifies the default media type for the request body. It determines how the content is formatted when sent to the API.
  • Set the default accept header for incoming requests in the code view by using defaultAcceptHeader, or in the form view, under Default accept header, which is an optional field.

    This field defines the default accept header, which specifies the expected media types for the response to be received.

As both these properties support a variable framework, you can use the available variables to specify the content type and accept header.