mockfly logo

Import Project from JSON

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.

JSON Structure

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": []
        }
      ]
    }
  ]
}

Field Descriptions

  • project.name: The name of the project to be created.
  • endpoints: An array of endpoint objects.
  • endpoints[].method: HTTP method (GET, POST, PUT, DELETE, PATCH, OPTIONS, HEAD).
  • endpoints[].path: The URL path for the endpoint (e.g., /users/:id).
  • endpoints[].delay: Response delay in milliseconds.
  • endpoints[].responses: Array of possible responses for the endpoint.
  • endpoints[].responses[].status: HTTP status code (e.g., 200, 404).
  • endpoints[].responses[].body: The JSON body of the response.
  • endpoints[].responses[].rules: Conditions that must be met for this response to be served.