new Response(options)
Response holds data related to the request body. By default, it provides a nice wrapper for url-encoded, form-data, and raw types of request bodies.
Parameters:
Name | Type | Description |
---|---|---|
options |
Response.definition |
- Source:
Extends
Members
body :String
Type:
- String
- Source:
code :Number
Type:
- Number
- Source:
cookies :CookieList
Type:
- Source:
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
- Inherited From:
- Source:
headers :HeaderList
Type:
- 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:
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:
originalRequest :Request
Type:
- Source:
responseTime :Number
Time taken for the request to complete.
Type:
- Number
- Source:
status :String
Type:
- String
- Source:
Methods
(static) createFromNode(response, cookies) → {Object}
Converts the response object from the request module to the postman responseBody format
Parameters:
Name | Type | Description |
---|---|---|
response |
Object | The response object, as received from the request module |
cookies |
Object |
- Source:
- To Do:
-
- Add a key: `originalRequest` to the returned object as well, referring to response.request
Returns:
The transformed responseBody
- Type
- Object
(static) isResponse(obj) → {Boolean}
Check whether an object is an instance of ItemGroup.
Parameters:
Name | Type | Description |
---|---|---|
obj |
* |
- Source:
Returns:
- Type
- Boolean
contentInfo() → {Response.ResponseContentInfo}
Extracts mime type, format, charset, extension and filename of the response content A fallback of default filename is given, if filename is not present in content-disposition header
- Source:
Returns:
- contentInfo for the response
dataURI() → {String}
Converts the response to a dataURI that can be used for storage or serialisation. The data URI is formed using
the following syntax data:<content-type>;baseg4, <base64-encoded-body>
.
- Source:
- To Do:
-
- write unit tests
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 |
String |
<optional> |
"text/plain" | The type of the content. |
- Inherited From:
- Source:
Example
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(options, iterator)
Invokes the given iterator for every parent in the parent chain of the given element.
Parameters:
Name | Type | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object | A set of options for the parent chain traversal. Properties
|
||||||||||
iterator |
function | The function to call for every parent in the ancestry chain. |
- Inherited From:
- Source:
- To Do:
-
- Cache the results
json(reviveropt, strictopt) → {Object}
Get the response body as a JavaScript object. Note that it throws an error if the response is not a valid JSON
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
reviver |
function |
<optional> |
||
strict |
Boolean |
<optional> |
false | Specify whether JSON parsing will be strict. This will fail on comments and BOM |
- Source:
Returns:
- Type
- Object
Example
// assuming that the response is stored in a collection instance `myCollection`
var response = myCollection.items.one('some request').responses.idx(0),
jsonBody;
try {
jsonBody = response.json();
}
catch (e) {
console.log("There was an error parsing JSON ", e);
}
// log the root-level keys in the response JSON.
console.log('All keys in json response: ' + Object.keys(json));
jsonp(reviveropt, strictopt)
Get the JSON from response body that reuturns JSONP response.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
reviver |
function |
<optional> |
||
strict |
Boolean |
<optional> |
false | Specify whether JSON parsing will be strict. This will fail on comments and BOM |
- Source:
Throws:
-
when response body is empty
- Type
- JSONError
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
reason() → {String|undefined}
Get the http response reason phrase based on the current response code.
- Source:
Returns:
- Type
- String | undefined
size() → {Number}
Get the response size by computing the same from content length header or using the actual response body.
- Source:
- To Do:
-
- write unit tests
Returns:
- Type
- Number
text() → {String|undefined}
Get the response body as a string/text.
- Source:
Returns:
- Type
- String | undefined
toJSON() → {Object}
Convert this response into a JSON serializable object. The _details meta property is omitted.
- Overrides:
- Source:
- To Do:
-
- consider switching to a different response buffer (stream) representation as Buffer.toJSON appears to cause multiple performance issues.
Returns:
- Type
- Object
Type Definitions
definition
Properties:
Name | Type | Attributes | Description |
---|---|---|---|
code |
Number | define the response code |
|
reason |
String |
<optional> |
optionally, if the response has a non-standard response code reason, provide it here |
header |
Array.<Header.definition> |
<optional> |
|
cookie |
Array.<Cookie.definition> |
<optional> |
|
body |
String |
<optional> |
|
stream |
Buffer | ArrayBuffer |
<optional> |
|
responseTime |
Number |
- Source:
- To Do:
-
- pluralise `header`, `cookie`
ResponseContentInfo
Properties:
Name | Type | Description |
---|---|---|
mimeType |
String | sanitized mime type |
mimeFormat |
String | format for the identified mime type |
charset |
String | the normalized character set |
fileExtension |
String | extension identified from the mime type |
fileName |
String | file name extracted from disposition header |
contentType |
String | sanitized content-type extracted from header |
- Source:
timings
Returns the durations of each request phase in milliseconds
Properties:
Name | Type | Description | |||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
start |
Number | timestamp of the request sent from the client (in Unix Epoch milliseconds) |
|||||||||||||||||||||||||||
offset |
Object | event timestamps in millisecond resolution relative to start Properties
|
- Source:
Example
Output
Request.timingPhases(timings);
{
prepare: Number, // duration of request preparation
wait: Number, // duration of socket initialization
dns: Number, // duration of DNS lookup
tcp: Number, // duration of TCP connection
secureHandshake: Number, // duration of secure handshake
firstByte: Number, // duration of HTTP server response
download: Number, // duration of HTTP download
process: Number, // duration of response processing
total: Number // duration entire HTTP round-trip
}