You are browsing documentation for an outdated plugin version.
Looking for the plugin's configuration parameters? You can find them in the Mocking configuration reference doc.
Provide mock endpoints to test your APIs in development against your services. The Mocking plugin leverages standards based on the Open API Specification (OAS) for sending out mock responses to APIs. Mocking supports both Swagger 2.0 and OpenAPI 3.0.
Benefits of service mocking with the Kong Mocking plugin:
- Conforms to a design-first approach since mock responses are within OAS.
- Accelerates development of services and APIs.
- Promotes parallel development of APIs across distributed teams.
- Easily enable and disable the Mocking plugin for flexibility when testing API behavior.
This plugin can mock 200
, 201
, and 204
responses.
Note: The plugin requires a spec to work. Depending on the Kong Gateway deployment mode, set either the
api_specification_filename
or theapi_specification
parameter.
Behavioral Headers
Behavioral headers allow you to change the behavior of the Mocking plugin for the individual request without changing the configuration.
X-Kong-Mocking-Delay
The X-Kong-Mocking-Delay
header tells the plugin how many milliseconds to delay before responding. The delay value must be between 0
(inclusive) and 10000
(inclusive), otherwise it returns a 400
error.
HTTP/1.1 400 Bad Request
{
"message": "Invalid value for X-Kong-Mocking-Delay. The delay value should between 0 and 10000ms"
}
X-Kong-Mocking-Example-Id
The X-Kong-Mocking-Example-Id
header tells the plugin which response example is used when the endpoint has multiple examples for a single status code.
OpenAPI 3.0 allows you to define multiple examples in a single MIME type. The following example has two candidate examples: Hao
and Sasha
.
paths:
/query_user:
get:
responses:
'200':
description: A user object.
content:
application/json:
examples:
Hao:
value:
id: 10
name: Hao
Sasha:
value:
id: 20
name: Sasha
Makes a request to choose a specific example to respond to:
curl -X GET http://HOSTNAME:8000/query_user -H "X-Kong-Mocking-Example-Id: Sasha"
Response:
{
"id": 20,
"name": "Sasha"
}
X-Kong-Mocking-Status-Code
By default, the plugin chooses the minimum status code that is defined in the corresponding method.
The X-Kong-Mocking-Status-Code
header allows requests to change the default status code selection behavior by specifying a status code that is defined in the corresponding method.
paths:
/ping:
get:
responses:
'200':
description: '200'
content:
application/json:
example:
message: '200'
'500':
description: '500'
content:
application/json:
example:
message: '500'
Makes a request to choose a specific status code to respond to:
curl -i -X GET http://HOSTNAME:8000/ping -H "X-Kong-Mocking-Status-Code: 500"
Response:
HTTP/1.1 500 Internal Server Error
{
"message": "500"
}