Mockfly allows you to import a project from a JSON file. This is particularly useful if you want to migrate data from another tool, restore a backup, or simply create a project manually or programmatically.
To import a project, simply go to the projects page and look for the "Import Project" button. You can upload a JSON file or paste the JSON content directly.
The JSON file must follow a specific structure to be correctly interpreted by Mockfly. Below is an example of a valid JSON file for importing a project including endpoints, rules, and responses.
{
"project": {
"name": "E-commerce API"
},
"endpoints": [
{
"method": "GET",
"path": "/products",
"delay": 0,
"returnRandomResponse": false,
"proxyConfiguration": "default",
"headers": [],
"responses": [
{
"status": 200,
"body": {
"products": [
{ "id": 1, "name": "Laptop", "price": 999 },
{ "id": 2, "name": "Smartphone", "price": 599 }
]
},
"isEnabled": true,
"rules": []
}
]
},
{
"method": "GET",
"path": "/products/:id",
"delay": 500,
"returnRandomResponse": false,
"proxyConfiguration": "default",
"headers": [],
"responses": [
{
"status": 200,
"body": {
"id": "{{:id}}",
"name": "Laptop",
"price": 999,
"description": "High performance laptop"
},
"isEnabled": true,
"rules": []
},
{
"status": 404,
"body": {
"error": "Product not found"
},
"isEnabled": true,
"rules": [
{
"property": "id",
"comparator": "equal",
"value": "999",
"source": "params",
"andConditions": [],
"position": 0
}
]
}
]
},
{
"method": "POST",
"path": "/orders",
"delay": 200,
"returnRandomResponse": false,
"proxyConfiguration": "default",
"headers": [
{
"key": "Location",
"value": "/orders/123"
}
],
"responses": [
{
"status": 201,
"body": {
"message": "Order created successfully",
"orderId": 123
},
"isEnabled": true,
"rules": []
}
]
}
]
}