Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
newman-collection
Advanced tools
This module will bring your postman/newman experience to a next level
npm i newman-collection
The only feature this module brings is simplified minimalistic JS-like creation of the collection file.
Newman is a tool developed by a postman team works with existing files or URL in CLI mode or with a model from postman-collection module as node.js module. This module is nothing more than decoration of postman-collection calls.
const { Collection, Item } = require("newman-collection");
const newman = require("newman");
let oCollection = new Collection([
// test GET
new Item("Test GET request")
.get("https://postman-echo.com/get?foo1=bar1&foo2=bar2")
.pm.test("This is test A", () => {
pm.response.to.be.ok;
})
.pm.test("This is test B", () => {
pm.response.to.be.ok;
}),
// test POST
new Item("Test POST request")
.post("https://postman-echo.com/post")
.headers({ "Content-Type": "text/plain" })
.body("test")
.pm.test("body should be same", () => {
pm.response.to.have.jsonBody("data", "test");
}),
// test auth
new Item("Test basic auth")
.get("https://postman-echo.com/basic-auth")
.auth.basic({ username: "postman", password: "password" })
.pm.test("Must be authenticated", () => {
pm.response.to.have.jsonBody("authenticated", true);
})
]);
newman.run({
collection: oCollection.collection,
reporters: ["cli"]
});
method | description |
---|---|
basic({username,password}) | Provides basic authentication. Do not use secret data in your code but use {{secret}} variables instead. |
method | description |
---|---|
constructor( collection?: CollectionDefinition , items?: Item ) | To create an instance you can provide collection definition from postman SDK. In addition to this list of items can be provided also |
constructor( items*?: Item ) | You can omit definition part providing just array of items |
set items(items: Item) { | A setter method is also availabe to set items later |
auth | Returns auth interface. Please see section above. When using auth on the collection level credentials will be applied to all requests in the collection |
method | description |
---|---|
get/post/head/options/put/delete/patch (url:string) | these are factory functions for Request of a certain type |
auth | See auth section |
method | description |
---|---|
body(body:string|object) | Sets body, converts to JSON if needed |
headers(headers: object) | Sets request headers in a similar to fetch API way |
auth.basic({username,password}) | Provides basic authentication. Do not use secret data in your code but use {{secret}} variables instead. |
on.prerequest(callback:Function) | This function along with test script also is probably the main purpose of this module creation. It is extremely not convenient to work with a collection file editing script as string data, not a code. |
on.test(callback:Function) | test script writer, same as prerequest |
pm.test(description, callback) | Even more simplified way of creating test scripts. This is what it does: will create JSON like this: and finally in the console we can have this: |
auth | see auth section |
FAQs
> This module will bring your postman/newman experience to a next level
The npm package newman-collection receives a total of 25 weekly downloads. As such, newman-collection popularity was classified as not popular.
We found that newman-collection demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.