All Products
Search
Document Center

API Gateway:Mock

Last Updated:Dec 15, 2023

In most cases, business partners work in combination to develop a project. The project development process is hindered due to the interdependence among business partners. Misunderstandings can also arise and affect the development progress or even cause severe delays to the project. Mock can be used early in the project development cycle to simulate activities and project results. This can greatly reduce miscommunication and misunderstanding among team members in the project development and greatly improve the development efficiency. API Gateway allows you to use Mock as the backend service of an API, which requires simple configurations.

Configure Mock

In the Define Backend Service step of the Create API wizard, set Backend Service Type to Mock and complete relevant configurations.

1. Specify a Mock response

Configure a response for the API. The response is returned for all requests for the API. You can specify a Mock response in various formats, such as JSON, XML, and text. Example:

{
    "result": {
        "title": " Mock test for API Gateway",
        ...
    }
}

After you create an API that uses Mock as the backend service type, you can publish the API to the test or production environment. You can also go to the debugging page to debug the API.

2. Specify the HTTP status code

The following table lists the valid HTTP status codes. HTTP/1.1 status codes are supported. If you enter a code that is not in the following table, a message that indicates that the code you entered is invalid appears.

http 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

API Gateway supports custom Mock header fields and duplicate header field names. A header field name cannot be empty and can contain digits, letters, underscores (_), and hyphens (-). The value of a header field cannot be empty.

Remove Mock

If you do not want to use Mock as the backend service type of an API, you only need to configure a different backend service type for the API. The Mock configurations are retained for your convenient future reference. After you change the backend service type, you must publish the API to enable the change to take effect.