{"id":20104829,"url":"https://github.com/theplenkov-npm/newman-collection","last_synced_at":"2026-04-18T12:03:50.053Z","repository":{"id":38774546,"uuid":"240966201","full_name":"theplenkov-npm/newman-collection","owner":"theplenkov-npm","description":"Minimalistic Postman/Newman collections generator","archived":false,"fork":false,"pushed_at":"2022-06-23T18:43:55.000Z","size":105,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-10T18:37:37.621Z","etag":null,"topics":["http-testing","newman","postman","postman-collection"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/theplenkov-npm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-02-16T21:09:11.000Z","updated_at":"2022-06-23T17:20:02.000Z","dependencies_parsed_at":"2022-09-18T17:02:50.643Z","dependency_job_id":null,"html_url":"https://github.com/theplenkov-npm/newman-collection","commit_stats":null,"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"purl":"pkg:github/theplenkov-npm/newman-collection","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theplenkov-npm%2Fnewman-collection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theplenkov-npm%2Fnewman-collection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theplenkov-npm%2Fnewman-collection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theplenkov-npm%2Fnewman-collection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/theplenkov-npm","download_url":"https://codeload.github.com/theplenkov-npm/newman-collection/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/theplenkov-npm%2Fnewman-collection/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31967993,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-18T00:39:45.007Z","status":"online","status_checked_at":"2026-04-18T02:00:07.018Z","response_time":103,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["http-testing","newman","postman","postman-collection"],"created_at":"2024-11-13T17:44:55.583Z","updated_at":"2026-04-18T12:03:50.025Z","avatar_url":"https://github.com/theplenkov-npm.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Newman/Postman collection generator\n\n\u003e This module will bring your postman/newman experience to a next level\n\n[![NPM Version][npm-image]][npm-url]\n\n## Install\n\n```bash\nnpm i newman-collection\n```\n\n## Usage\n\nThe only feature this module brings is simplified minimalistic JS-like creation of the collection file.\n\nNewman is a tool developed by a postman team which can run existing  collections . Having postman-collection SDK available we can already generate collections on the fly, however working with this library directly developer experience was not that great. Behind the idea of this module I have personal experience of working with Express.js (get/post/head/put/delete and other https methods), fetch Web API-like headers declaration and finally writing scripts as Javascript not like strings\n\nSame code with postman SDK will take more lines:\n\n```js\nconst { Collection, Item } = require(\"newman-collection\");\nconst newman = require(\"newman\");\n\nlet oCollection = new Collection([\n  // test GET\n  new Item(\"Test GET request\")\n    .get(\"https://postman-echo.com/get?foo1=bar1\u0026foo2=bar2\")\n    .pm.test(\"This is test A\", () =\u003e {\n      pm.response.to.be.ok;\n    })\n    .pm.test(\"This is test B\", () =\u003e {\n      pm.response.to.be.ok;\n    }),\n  // test POST\n  new Item(\"Test POST request\")\n    .post(\"https://postman-echo.com/post\")\n    .headers({ \"Content-Type\": \"text/plain\" })\n    .body(\"test\")\n    .pm.test(\"body should be same\", () =\u003e {\n      pm.response.to.have.jsonBody(\"data\", \"test\");\n    }),\n  // test auth\n  new Item(\"Test basic auth\")\n    .get(\"https://postman-echo.com/basic-auth\")\n    .auth.basic({ username: \"postman\", password: \"password\" })\n    .pm.test(\"Must be authenticated\", () =\u003e {\n      pm.response.to.have.jsonBody(\"authenticated\", true);\n    })\n]);\n\nnewman.run({\n  collection: oCollection.collection,\n  reporters: [\"cli\"]\n});\n```\n\n#### Interface auth\n\n| method                     | description                                                                                              |\n| -------------------------- | -------------------------------------------------------------------------------------------------------- |\n| basic({username,password}) | Provides basic authentication. Do not use secret data in your code but use {{secret}} variables instead. |\n\n#### class Collection\n\n| method                                                                | description                                                                                                                                             |\n|:--------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| _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                    |\n| _constructor_( items\\*?: Item )                                       | You can omit definition part providing just array of items                                                                                              |\n| _set_ items(_items_: Item) {                                          | A setter method is also availabe to set items later                                                                                                     |\n| 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 |\n\n#### class Item\n\n| method                                              | description                                               |\n| --------------------------------------------------- | --------------------------------------------------------- |\n| get/post/head/options/put/delete/patch (url:string) | these are factory functions for Request of a certain type |\n| auth                                                | See auth section                                          |\n\n#### interface Request\n\n| method                           | description                                                                                                                                                                                                                                                                                                                                                                   |\n| -------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| body(body:string\\|object)        | Sets body, converts to JSON if needed                                                                                                                                                                                                                                                                                                                                         |\n| headers(headers: object)         | Sets request headers in a similar to fetch API way                                                                                                                                                                                                                                                                                                                            |\n| auth.basic({username,password})  | Provides basic authentication. Do not use secret data in your code but use {{secret}} variables instead.                                                                                                                                                                                                                                                                      |\n| 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.                                                                                                                                                                      |\n| on.test(callback:Function)       | test script writer, same as prerequest                                                                                                                                                                                                                                                                                                                                        |\n| pm.test(description, callback)   | Even more simplified way of creating test scripts. This is what it does:\u003cbr/\u003e ![image-20200218170449413](docs/img/image-20200218170449413.png)\u003cbr/\u003e will create JSON like this:\u003cbr/\u003e ![image-20200218180458079](docs/img/image-20200218180458079.png)\u003cbr/\u003e and finally in the console we can have this:\u003cbr/\u003e ![image-20200218170733249](docs/img/image-20200218170733249.png) |\n| auth                             | see auth section                                                                                                                                                                                                                                                                                                                                                              |\n\n## Extensibility\n\nYou can always use these classes to build your own recipies and then reuse them across your scenarios\n\n```js\nconst { Collection, Item } = require(\"newman-collection\");\n\n// Odata login: fetching X-CSRF-Token for future reusing it in the collection with embedded test\nclass OdataLogin extends Item {\n  request(...args) {\n    return super\n      .request(...args)\n      .headers({ \"X-CSRF-Token\": \"fetch\" })\n      .pm.test(\"Token must be fetched\", () =\u003e {\n        pm.response.to.be.ok;\n        pm.response.to.have.header(\"x-csrf-token\");\n        pm.variables.set(\n          \"x-csrf-token\",\n          pm.response.headers.get(\"x-csrf-token\")\n        );\n      });\n  }\n}\n\n// Odata call, CSRF token provided + expects json back\nclass OdataCall extends Item {\n  request(...args) {\n    return super.request(...args).headers({\n      \"X-CSRF-Token\": \"{{x-csrf-token}}\",\n      Accept: \"application/json\"\n    });\n  }\n}\n```\n\n## Important links:\n\n[Newman API - CLI/Node.js postman collections runner](https://github.com/postmanlabs/newman)\n\n[Postman SDK - Model this extension is built on top of](http://www.postmanlabs.com/postman-collection/index.html)\n\n[Postman Sandbox API Reference (pm.)](https://learning.postman.com/docs/postman/scripts/postman-sandbox-api-reference/)\n\n[Postman Echo Test Service](https://docs.postman-echo.com/)\n\n## License\n\n[MIT](http://vjpr.mit-license.org)\n\n[npm-image]: https://img.shields.io/npm/v/newman-collection.svg\n[npm-url]: https://npmjs.org/package/newman-collection\n[travis-image]: https://img.shields.io/travis/live-js/newman-collection/master.svg\n[coveralls-image]: https://img.shields.io/coveralls/live-js/newman-collection/master.svg\n[coveralls-url]: https://coveralls.io/r/live-js/newman-collection?branch=master\n[postman-collection]: https://github.com/postmanlabs/postman-collection\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheplenkov-npm%2Fnewman-collection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftheplenkov-npm%2Fnewman-collection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftheplenkov-npm%2Fnewman-collection/lists"}