Header

Header

Represents an HTTP header, for requests or for responses.

Parameters:
Name Type Attributes Description
options Header~definition | String

Pass the header definition as an object or the value of the header. If the value is passed as a string, it should either be in name:value format or the second "name" parameter should be used to pass the name as string

name String <optional>

optional override the header name or use when the first parameter is the header value as string.

Source:
Example

Parse a string of headers into an array of Header objects

var Header = require('postman-collection').Header,
    headerString = 'Content-Type: application/json\nUser-Agent: MyClientLibrary/2.0\n';

var rawHeaders = Header.parse(headerString);
console.log(rawHeaders); // [{ 'Content-Type': 'application/json', 'User-Agent': 'MyClientLibrary/2.0' }]

var headers = rawHeaders.map(function (h) {
    return new Header(h);
});

function assert(condition, message) {
      if (!condition) {
          message = message || "Assertion failed";
          if (typeof Error !== "undefined") {
              throw new Error(message);
          }
          throw message; //fallback
      }
      else {
          console.log("Assertion passed");
      }
  }

assert(headerString.trim() === Header.unparse(headers).trim());

Extends

Members

disabled :Boolean

This (optional) flag denotes whether this property is disabled or not. Usually, this is helpful when a property is part of a PropertyList. For example, in a PropertyList of Headers, the ones that are disabled can be filtered out and not processed.

Type:
  • Boolean
Overrides:
Source:

id :String

The id of the property is a unique string that identifies this property and can be used to refer to this property from relevant other places. It is a good practice to define the id or let the system auto generate a UUID if one is not defined for properties that require an id.

Type:
  • String
Inherited From:
Source:

key :String

The header Key

Type:
  • String
Source:

name :String

A property can have a distinctive and human-readable name. This is to be used to display the name of the property within Postman, Newman or other runtimes that consume collection. In certain cases, the absence of name might cause the runtime to use the id as a fallback.

Type:
  • String
Inherited From:
Source:

value :String

The header value

Type:
  • String
Source:

Methods

(static) create(valueopt, nameopt) → {Header}

Create a new header instance

Parameters:
Name Type Attributes Description
value Header~definition | String <optional>

Pass the header definition as an object or the value of the header. If the value is passed as a string, it should either be in name:value format or the second "name" parameter should be used to pass the name as string

name String <optional>

optional override the header name or use when the first parameter is the header value as string.

Source:
Returns:
Type
Header

(static) isHeader(obj) → {Boolean}

Check whether an object is an instance of PostmanHeader.

Parameters:
Name Type Description
obj *
Source:
Returns:
Type
Boolean

(static) parse(headerString) → {Array}

Parses a multi line header string into an array of Header~definition.

Parameters:
Name Type Description
headerString String
Source:
Returns:
Type
Array

(static) parseSingle(header) → {Object}

Parses a single Header.

Parameters:
Name Type Description
header String
Source:
Returns:
Type
Object

(static) unparse(headers, separatoropt) → {string}

Stringifies an Array or PropertyList of Headers into a single string.

Parameters:
Name Type Attributes Description
headers Array | PropertyList.<Header>
separator String <optional>

Specify a string for separating each header, by default, '\n', but sometimes, it might be more useful to use a carriage return ('\r\n')

Source:
Returns:
Type
string

(static) unparseSingle(header) → {String}

Unparses a single Header.

Parameters:
Name Type Description
header String
Source:
Returns:
Type
String

describe(content, typeopt)

This function allows to describe the property for the purpose of detailed identification or documentation generation. This function sets or updates the description child-property of this property.

Parameters:
Name Type Attributes Default Description
content String

The content of the description can be provided here as a string. Note that it is expected that if the content is formatted in any other way than simple text, it should be specified in the subsequent type parameter.

type String <optional>
"text/plain"

The type of the content can be one of the values mentioned in Description.format enumeration - namely text/plain, text/markdown or text/html.

Inherited From:
Source:
Example

Add a description to an instance of Collection

 var Collection = require('postman-collection').Collection,
    mycollection;

// create a blank collection
myCollection = new Collection();
myCollection.describe('Hey! This is a cool collection.');

console.log(myCollection.description.toString()); // read the description

findInParents(property, customizeropt) → {*|undefined}

Tries to find the given property locally, and then proceeds to lookup in each parent, going up the chain as necessary. Lookup will continue until customizer returns a truthy value. If used without a customizer, the lookup will stop at the first parent that contains the property.

Parameters:
Name Type Attributes Description
property String
customizer function <optional>
Inherited From:
Source:
Returns:
Type
* | undefined

forEachParent(optionsopt, iterator)

Invokes the given iterator for every parent in the parent chain of the given element.

Parameters:
Name Type Attributes Default Description
options Object | Boolean <optional>
{}

A set of options for the parent chain traversal.

Properties
Name Type Attributes Default Description
withRoot Boolean <optional>
<nullable>
false

Set to true to include the collection object as well.

iterator function

The function to call for every parent in the ancestry chain.

Inherited From:
Source:
To Do:
  • Cache the results

meta() → {*}

Returns the meta keys associated with the property

Inherited From:
Source:
Returns:
Type
*

parent() → {*|undefined}

Returns the parent of item

Inherited From:
Source:
Returns:
Type
* | undefined

toJSON()

Returns the JSON representation of a property, which conforms to the way it is defined in a collection. You can use this method to get the instantaneous representation of any property, including a Collection.

Inherited From:
Source:

toString() → {String}

Converts the header to a single header string.

Source:
Returns:
Type
String

update(options)

Assigns the given properties to the Header

Parameters:
Name Type Description
options Object
Source:

valueOf() → {String}

Return the value of this header.

Source:
Returns:
Type
String

Type Definitions

definition

Properties:
Name Type Description
key String

The Header name (e.g: 'Content-Type')

value String

The value of the header.

Source:
Example

Create a header

var Header = require('postman-collection').Header,
    header = new Header({
        key: 'Content-Type',
        value: 'application/xml'
    });

console.log(header.toString()) // prints the string representation of the Header.