Class BodyElement


public class BodyElement extends CollectionElement

Encapsulates the body property of a Request object.

Postman SDK analog: RequestBody

There are several different permutations for this property depending on the

mode selected in Postman. Some examples:

plaintext:
 "body": {
   "mode": "raw",
     "raw": "This is some text in the body"
   }
   
Form data Formdata and Urlencoded bodies comprise an array of key value pairs persisted as instance of Property:
    "body": {
        "mode": "urlencoded",
        "urlencoded": [
            {
                "key": "x-field-1",
                "value": "x-field-1 value",
                "description": "This is x-field-1",
                "type": "text"
            },
            {
                "key": "x-field-2",
                "value": "x-field-2 value",
                "description": "This is x-field-2",
                "type": "text"
            },
            {
                "key": "x-field-3",
                "value": "{{Xfield3value}}",
                "description": "variable",
                "type": "text"
            }
            ]
        }
RAW options

Other forms of textual data contain an options property which only includes the langauge of the payload, e.g., javascript

    "body": {
        "mode": "raw",
        "raw": "pm.test(\"Status code is 200\", function () {\n ...",
        "options": {
            "raw": {
                "language": "javascript"
            }
        }
    }
    

GraphQL

GraphQL includes query and variable properties

    "body": {
        "mode": "graphql",
            "graphql": {
            "query": "query ($limit: Int!) {\n  ...",
            "variables": "{\n    \"limit\":2\n}"
            }
    }
    

Binary

Binary bodies contain a single src property with a path to the file

    "body": {
        "mode": "file",
        "file": {
            "src": "8vhckkNqZ/jenkins-small.png"
        }
    }
    
  • Constructor Details

    • BodyElement

      public BodyElement(enumRequestBodyMode mode, String content, enumRawBodyLanguage language)
      Constructs a body with the provided mode, content, and language. If mode is not raw, the language value is discarded.
      Parameters:
      mode - Enumerated value for the underying mode property of this request body
      content - The content in the body
      language - For bodies with mode RAW, the language of the body content, e.g., javascript
    • BodyElement

      public BodyElement(enumRequestBodyMode mode)
      Convenience constructor, creates an empty body object of the specified mode
      Parameters:
      mode - Enumerated value for the mode property
  • Method Details