Ana içeriğe geç

Create or Update Mock API

Endpoint​

POST /apiops/projects/{projectName}/mockapis/{mockApiName}/

Authentication​

Requires a Personal API Access Token.

Authorization: Bearer YOUR_TOKEN
Content-Type: application/json

Request​

Headers​

HeaderValueRequired
AuthorizationBearer {token}Yes
Content-Typeapplication/jsonYes

Path Parameters​

ParameterTypeRequiredDescription
projectNamestringYesProject name
mockApiNamestringYesName of the Mock API to create or update

Request Body​

The body is a full Mock API definition. It has the same fields as the object that Get Mock API returns. The example below is shortened.

{
"description": "Mock of the customer accounts service",
"version": "1.0.0",
"methodDefList": [
{
"id": "3f7c2a4e-7d0b-4a51-9a8e-0c1d2e3f4a5b",
"name": "/customers/{id}",
"httpMethod": "GET",
"description": "Returns one customer",
"responseList": [
{
"uuid": "8b0e5f3a-2c4d-4e6f-8a1b-3c5d7e9f1a2b",
"httpStatusCode": "OK",
"description": "Customer found",
"exampleList": [
{
"uuid": "1d2e3f4a-5b6c-4d7e-8f9a-0b1c2d3e4f5a",
"responseContentType": "application/json",
"responseBody": "{\"id\": 1, \"name\": \"Customer 1\"}"
}
]
}
]
}
]
}

Apinizer sets these fields itself:

FieldValue
nameThe mockApiName path parameter. A name in the body is ignored.
projectIdThe ID of the project in the projectName path parameter
idThe ID of the existing Mock API with the same name in the project. If the project has no such Mock API, Apinizer creates a new ID.

If version is empty, the Mock API returns the version 1.0.

Response​

Success Response (200 OK)​

The saved Mock API is returned as the single element of resultList.

{
"status": "SUCCESS",
"resultMessage": "MockAPI saved successfully.",
"resultList": [
{
"id": "66f1c0a2e4b0a1b2c3d4e5f6",
"name": "Customer Accounts",
"description": "Mock of the customer accounts service",
"version": "1.0.0",
"projectId": "66f1bf10e4b0a1b2c3d4e5a1",
"methodDefList": [ ... ]
}
]
}

Error Response (400 Bad Request)​

The user does not have the required permission, or the project does not exist.

{
"status": "FAILURE",
"resultMessage": "User does not have required permission for this operation!"
}

Error Response (400 Bad Request) - Size Limit​

A Mock API can be at most 10 MB. Apinizer measures the size of the whole definition in UTF-8 bytes, and escape characters count too. If the saved definition is larger, the endpoint returns 400 and keeps the stored Mock API as it is. A Mock API that is already larger than 10 MB stays readable, but a new save is refused until its content is below 10 MB.

Error Response (401 Unauthorized)​

The token is missing or not valid. For the error format, see Error Handling.

cURL Example​

curl -X POST \
"https://demo.apinizer.com/apiops/projects/MyProject/mockapis/Customer%20Accounts/" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d @customer-accounts-mock-api.json

Notes and Warnings​

  • Full replacement: The body replaces the whole definition of an existing Mock API. Endpoints that are not in the body are removed.
  • No validation of endpoints: Apinizer does not check the endpoints in the body. For example, it does not reject two endpoints with the same method and path. Send a definition that you took from Get Mock API.
  • Size limit: A Mock API can be at most 10 MB, counted as the UTF-8 bytes of the whole definition. A reverse proxy in front of the Manager can also reject a large request with 413.
  • No redeploy: Saving does not redeploy the API Proxies of the Mock API. To apply the changes, redeploy these API Proxies.

Permissions​

  • User must have API_CREATOR + MANAGE permission in the project