1.1.2 • Published 10 months ago

@deskree/postman-collection-generator v1.1.2

Weekly downloads
-
License
ISC
Repository
github
Last release
10 months ago

postman-collection-generator

This package generates postman collection from express controllers.

Installing

Install package as a dev dependency via npm.

npm install --save @deskree/postman-collection-generator

Import package either into the base class of your controllers or to each controller individually:

import {PostmanControllerInterface} from "@deskree/postman-collection-generator";

Using

Controller Data Structure

postman-collection-generator creates postman collections from express controllers. In order for the collection and items to be generated correctly, each controller has to be a class that implements a PostmanControllerInterface and have the appropriate data structure. See example below:

// exampleController.ts
import {PostmanControllerInterface} from "@deskree/postman-collection-generator";

export class ExampleController implements PostmanControllerInterface {

    public name = 'Example Name of Postman Folder';
    public description = 'Example Description of Postman Folder';
    public routes = [
        {
            name: 'GET Something by id',
            url: '/example/{{id}}',
            method: 'GET',
            description: 'Get something from somewhere by some id',
            params: ['some_param=123'],
            headers: [{ key: 'Content-Type', value: 'application/json' }]
        },
        {
            name: 'Create Product',
            url: '/product',
            method: 'POST',
            body: {
                product: {
                    title: "Product Name",
                    price: 12,
                    tags: [
                        "Product"
                    ]
                }
            }
        }
    ]

    ...

Overall Data Structure

ParameterTypeRequiredDescription
namestringyesName of Postman folder (itemsGroup)
descriptionstringnoDescription of Postman folder (itemsGroup)
routesarrayyesList of Postman requests (items)

routes Data Structure

ParameterTypeRequiredDescription
namestringyesName of Postman request
descriptionstringnoDescription of Postman request
urlstringyesPostman request URL
methodstringyesPostman request method (ex. GET, POST, PUT, DELETE)
paramsarray of stringsnoList of postman request parameters
headersarray of objectsnoList of postman request headers. Each header must have the following structure: { key: 'Some header key', value: 'some header value' }
bodyobjectnoBody of postman request

Configure package.json

In order to run postman-collection-generator, just add the following line into your package.json's "scripts" with appropriate parameters. Example:

...
"scripts": {
    "postman": "postman-generator --folder src/controllers --outputDir ./ --integrationName Example --baseURL https://user.deskree.com/api/v1"
}
...

Command parameters:

ParameterTypeRequiredDescription
--folderstringyesFolder with your controllers
--outputDirstringyesFolder where you want to save the postman collection
--integrationNamestringyesName of your postman collection
--baseURLstringyesBase url for all requests within your collection

Run

Once everything is set up and package.json is configured, just run the following command to generate your Postman collection:

npm run postman

Output

The command will generate collection.json file in the specified folder. You can import this collection into Postman.

Built with

Authors

License

This project is licensed under the MIT License

1.1.2

10 months ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.29

1 year ago

1.0.30

1 year ago

1.0.28

1 year ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago