Mock simulates API responses during development, enabling parallel work across teams without waiting for backend services. API Gateway supports Mock as a backend service type with minimal configuration.
Configure Mock
In the Define Backend Service step of the Create API wizard, set Backend Service Type to Mock.
1. Specify a Mock response.
Define the response that API Gateway returns for all requests to this API. Supported formats include JSON, XML, and plain text. Example:
{
"result": {
"title": " Mock test for API Gateway",
...
}
}
After you create the API, publish it to the test or production environment, or debug it on the debugging page.
The size of a Mock response cannot exceed 50 KB.
2. Specify the HTTP status code.
The following HTTP/1.1 status codes are supported. Invalid codes are rejected.
|
HTTP status code |
HTTP message |
|
200 |
OK |
|
201 |
Created |
|
202 |
Accepted |
|
203 |
Non-Authoritative Information |
|
204 |
No Content |
|
205 |
Reset Content |
|
206 |
Partial Content |
|
300 |
Multiple Choices |
|
301 |
Moved Permanently |
|
302 |
Found |
|
303 |
See Other |
|
304 |
Not Modified |
|
305 |
Use Proxy |
|
306 |
(Unused) |
|
307 |
Temporary Redirect |
|
400 |
Bad Request |
|
401 |
Unauthorized |
|
402 |
Payment Required |
|
403 |
Forbidden |
|
404 |
Not Found |
|
405 |
Method Not Allowed |
|
406 |
Not Acceptable |
|
407 |
Proxy Authentication Required |
|
408 |
Request Timeout |
|
409 |
Conflict |
|
410 |
Gone |
|
411 |
Length Required |
|
412 |
Precondition Failed |
|
413 |
Request Entity Too Large |
|
414 |
Request-URI Too Long |
|
415 |
Unsupported Media Type |
|
416 |
Requested Range Not Satisfiable |
|
417 |
Expectation Failed |
|
450 |
Parameter Requried |
|
451 |
Method Connect Exception |
|
500 |
Internal Server Error |
|
501 |
Not Implemented |
|
502 |
Bad Gateway |
|
503 |
Service Unavailable |
|
504 |
Gateway Timeout |
|
505 |
HTTP Version Not Supported |
3. Specify Mock header fields.
You can add custom Mock header fields, including duplicate field names. Field names must be non-empty and contain only digits, letters, underscores (_), and hyphens (-). Field values must be non-empty.
Remove Mock
To stop using Mock, change the backend service type of the API. The Mock configurations are retained. Republish the API for the change to take effect.