{
  "version": 12,
  "name": "03_body_modes",
  "description": "Example: every way to send a body — raw JSON, raw form-urlencoded, raw XML, multipart (text + file fields) and a project file as the whole body. Uses files/customers.csv and files/payload.json from this project.",
  "globals": [
    {
      "name": "$baseUrl",
      "value": "https://httpbin.org"
    },
    {
      "name": "$customerName",
      "value": "Ann Example"
    }
  ],
  "globalFunctions": "// Assertion helpers, built on check(label, pass, details).\n// Each records a pass / fail line in the log and the report.\n// A failed one fails its step when the step is done;\n// the code keeps running. Change them or add your own.\n// r defaults to the last response.\n\nfunction assertTrue(value, label = \"is true\") {\n  return check(label, Boolean(value), { actual: value, expected: true });\n}\n\nfunction assertEqual(actual, expected, label = \"equals \" + JSON.stringify(expected)) {\n  return check(label, isEqual(actual, expected), { actual, expected });\n}\n\nfunction assertNotEqual(actual, unexpected, label = \"does not equal \" + JSON.stringify(unexpected)) {\n  return check(label, !isEqual(actual, unexpected), { actual, expected: \"not \" + JSON.stringify(unexpected) });\n}\n\n// text contains a part, or a list contains an item\nfunction assertContains(haystack, needle, label = \"contains \" + JSON.stringify(needle)) {\n  const pass = Array.isArray(haystack) ? haystack.some((x) => isEqual(x, needle)) : String(haystack).includes(needle);\n  return check(label, pass, { actual: haystack, expected: needle });\n}\n\nfunction assertMatch(text, regex, label = \"matches \" + regex) {\n  return check(label, new RegExp(regex).test(String(text)), { actual: text, expected: String(regex) });\n}\n\nfunction assertLessThan(actual, limit, label = \"< \" + limit) {\n  return check(label, Number(actual) < Number(limit), { actual, expected: \"< \" + limit });\n}\n\nfunction assertGreaterThan(actual, limit, label = \"> \" + limit) {\n  return check(label, Number(actual) > Number(limit), { actual, expected: \"> \" + limit });\n}\n\n// expected: 200, \"2xx\", or a list such as [200, 201]\nfunction assertStatus(expected, r = response) {\n  const list = [].concat(expected).map(String);\n  const status = String(r && r.status);\n  const pass = list.some((e) => e === status || (/^[1-5]xx$/i.test(e) && e[0] === status[0]));\n  return check(\"status is \" + list.join(\" or \"), pass, { actual: r && r.status, expected });\n}\n\nfunction assertTimeBelow(ms, r = response) {\n  return check(\"time < \" + ms + \" ms\", Boolean(r) && r.timeMs < ms, { actual: r && r.timeMs, expected: \"< \" + ms });\n}\n\n// without expected, the header only has to exist\nfunction assertHeader(name, expected, r = response) {\n  const value = r ? r.headers[String(name).toLowerCase()] : undefined;\n  if (expected === undefined) return check(\"header \" + name + \" exists\", value !== undefined, { actual: value });\n  return check(\"header \" + name + \" equals \" + expected, String(value) === String(expected), { actual: value, expected });\n}\n\n// e.g. assertJsonPath(\"$.items[0].id\", 42); without expected, the value only has to exist\nfunction assertJsonPath(path, expected, r = response) {\n  const value = jsonPath(path, r);\n  if (expected === undefined) return check(path + \" exists\", value !== undefined, { actual: value });\n  return check(path + \" equals \" + JSON.stringify(expected), isEqual(value, expected), { actual: value, expected });\n}\n\n// schema: a JSON Schema object\nfunction assertSchema(schema, r = response) {\n  const result = validateSchema(r, schema);\n  return check(\"matches the JSON Schema\", result.valid, { error: result.errors || undefined });\n}\n",
  "libraries": [],
  "activeEnvironment": "",
  "auth": {
    "type": "none"
  },
  "settings": {},
  "data": {
    "file": ""
  },
  "cookies": [],
  "tags": [
    "example",
    "body",
    "upload"
  ],
  "steps": [
    {
      "body": "{\n  \"name\": \"$customerName\",\n  \"active\": true,\n  \"tags\": [\"qa\", \"api\"]\n}",
      "bodyMode": "raw",
      "checks": [
        {
          "op": "equals",
          "path": "$.json.name",
          "target": "json",
          "value": "Ann Example"
        },
        {
          "op": "equals",
          "path": "$.json.active",
          "target": "json",
          "value": "true"
        },
        {
          "op": "length",
          "path": "$.json.tags",
          "target": "json",
          "value": "2"
        }
      ],
      "headers": [
        {
          "name": "Content-Type",
          "value": "application/json"
        }
      ],
      "id": "raw-json",
      "method": "POST",
      "name": "Raw JSON body",
      "type": "request",
      "url": "$baseUrl/post"
    },
    {
      "body": "user=ann&role=tester",
      "bodyMode": "raw",
      "checks": [
        {
          "op": "equals",
          "path": "$.form.user",
          "target": "json",
          "value": "ann"
        },
        {
          "op": "equals",
          "path": "$.form.role",
          "target": "json",
          "value": "tester"
        }
      ],
      "headers": [
        {
          "name": "Content-Type",
          "value": "application/x-www-form-urlencoded"
        }
      ],
      "id": "raw-form",
      "method": "POST",
      "name": "Raw form-urlencoded body",
      "type": "request",
      "url": "$baseUrl/post"
    },
    {
      "body": "<order id=\"7\"><item sku=\"QA-001\"/></order>",
      "bodyMode": "raw",
      "checks": [
        {
          "op": "contains",
          "path": "$.data",
          "target": "json",
          "value": "<order id=\"7\">"
        },
        {
          "op": "equals",
          "path": "$.headers.Content-Type",
          "target": "json",
          "value": "application/xml"
        }
      ],
      "headers": [
        {
          "name": "Content-Type",
          "value": "application/xml"
        }
      ],
      "id": "raw-xml",
      "method": "POST",
      "name": "Raw XML body",
      "type": "request",
      "url": "$baseUrl/post"
    },
    {
      "bodyMode": "multipart",
      "checks": [
        {
          "op": "equals",
          "path": "$.form.name",
          "target": "json",
          "value": "Ann Example"
        },
        {
          "op": "contains",
          "path": "$.files.customers",
          "target": "json",
          "value": "Cara Quality"
        },
        {
          "op": "matches",
          "path": "$.headers.Content-Type",
          "target": "json",
          "value": "^multipart/form-data; boundary="
        }
      ],
      "id": "multipart",
      "method": "POST",
      "multipart": [
        {
          "kind": "text",
          "name": "name",
          "value": "$customerName"
        },
        {
          "kind": "text",
          "name": "role",
          "value": "QA engineer"
        },
        {
          "kind": "file",
          "name": "customers",
          "value": "customers.csv"
        }
      ],
      "name": "Multipart: text fields + a file",
      "type": "request",
      "url": "$baseUrl/post"
    },
    {
      "bodyFile": {
        "contentType": "",
        "path": "payload.json"
      },
      "bodyMode": "file",
      "checks": [
        {
          "op": "equals",
          "path": "$.json.orderId",
          "target": "json",
          "value": "1001"
        },
        {
          "op": "length",
          "path": "$.json.items",
          "target": "json",
          "value": "2"
        },
        {
          "op": "contains",
          "path": "$.headers.Content-Type",
          "target": "json",
          "value": "application/json"
        }
      ],
      "id": "file-json",
      "method": "PUT",
      "name": "File as the whole body (JSON)",
      "type": "request",
      "url": "$baseUrl/put"
    },
    {
      "bodyFile": {
        "contentType": "text/plain",
        "path": "customers.csv"
      },
      "bodyMode": "file",
      "checks": [
        {
          "op": "equals",
          "path": "$.headers.Content-Type",
          "target": "json",
          "value": "text/plain"
        },
        {
          "op": "contains",
          "path": "$.data",
          "target": "json",
          "value": "id,name,email,country,plan"
        }
      ],
      "id": "file-csv-typed",
      "method": "PUT",
      "name": "File body with an explicit content type",
      "type": "request",
      "url": "$baseUrl/put"
    }
  ]
}
