Rest API mocking and intercepting in seconds. Replace the endpoint in the code and you are ready. It's that simple!
- Installation and Setup
- Create A Mock API
- Read a Mock API config
- Update a Mock API Config
- Delete A Mock API config
- How to use your mock config
- Clone the project
- Import and Sync go.mod dependencies
The project contains a manifest.yaml file for cloud-foundry users.
- Login to your cloud-foundry org and space.
- Execute
cf push
from the repository directory.
When your mock-api application is running, you can start using it and set up a new config.
POST
request to https://<host>/mockConfig
The request body should contain the following JSON template:
{
"post": {
"status": 201,
"body": {
"name": "[email protected]"
}
},
"delete": {
"status": 200,
"body": {
"name": "[email protected]"
}
},
"patch": {
"status": 200,
"body": {
"key": "value"
}
}
}
<method>
(post
/delete
/patch
) - (json object) contains the config (status
andbody
) of the configured method.status
- (int64) the expected response status of yourpost
/delete
requestsbody
- the expected response body of yourpost
/delete
requests (can be a json format)
{
"id": "32c079dc-a8e1-43d2-bbd0-cb3b2f18d3f8",
"post": {
"status": 201,
"body": {
"name": "[email protected]"
}
},
"delete": {
"status": 200,
"body": {
"name": "[email protected]"
}
},
"patch": {
"status": 200,
"body": {
"key": "value"
}
}
}
id
- (uuid) the unique id of your config, will be used for mocking your requests to the client and for setup/delete<method>
(post
/delete
/patch
) - (json object) contains the config (status
andbody
) of the configured method.status
- (int64) the expected response status of yourpost
/delete
requestsbody
- the expected response body of yourpost
/delete
requests (can be a json format)
GET
request to https://<host>/mockConfig?id=<uuid>
uuid
- is the unique id of your mock config
NOTE!
You can get all configurations in your app memory using the all=true
flag.
Example:
GET
request to https://<host>/mockConfig?all=true
After creating a mock api config, you can change its settings.
This can be used when running a dynamic test that its configurations need to be changed on runtime.
PATCH
request tohttps://<host>/mockConfig?id=<uuid>
id
- (uuid) the unique id of your config, which received on theBuild A Mock API
step The request body should contain the following JSON template:
{
"post": {
"status": 201,
"body": {
"name": "[email protected]"
}
},
"delete": {
"status": 400,
"body": {
"name": "[email protected]"
}
},
"patch": {
"status": 200,
"body": {
"key": "value"
}
}
}
<method>
(post
/delete
/patch
) - (json object) contains the config (status
andbody
) of the configured method.status
- (int64) the expected response status of yourpost
/delete
requestsbody
- the expected response body of yourpost
/delete
requests (can be a json format)
{
"id": "32c079dc-a8e1-43d2-bbd0-cb3b2f18d3f8",
"post": {
"status": 201,
"body": {
"name": "[email protected]"
}
},
"delete": {
"status": 200,
"body": {
"name": "[email protected]"
}
},
"patch": {
"status": 200,
"body": {
"key": "value"
}
}
}
id
- (uuid) the unique id of your config, will be used for mocking your requests to the client and for setup/delete<method>
(post
/delete
/patch
) - (json object) contains the config (status
andbody
) of the configured method.status
- (int64) the expected response status of yourpost
/delete
requestsbody
- the expected response body of yourpost
/delete
requests (can be a json format)
When finishing with the mock api config, remember to delete it in order to avoid overloading your application in-memory.
DELETE
request to https://<host>/mockConfig?id=<uuid>
uuid
- is the unique id of your mock config
NOTE!
You can delete all configurations in your app memory using the all=true
flag.
Example:
DELETE
request to https://<host>/mockConfig?all=true
OK 200
on success
POST
request tohttps://<host>/?id=<uuid>
id
- (uuid) the unique id of your config, which received on theBuild A Mock API
step
Status Code
: should be as defined earlier.- The request body should contain the
postResponseBody
defined earlier:
{
"name": "[email protected]"
}
DELETE
request tohttps://<host>/?id=<uuid>
id
- (uuid) the unique id of your config, which received on theBuild A Mock API
step.