Gathering detailed insights and metrics for postman-code-generators
Gathering detailed insights and metrics for postman-code-generators
Gathering detailed insights and metrics for postman-code-generators
Gathering detailed insights and metrics for postman-code-generators
@paloaltonetworks/postman-code-generators
Generates code snippets for a postman collection
postman-collection
Enables developers to use a unified Postman Collection format Object across projects
postman-url-encoder
Implementation of the WHATWG URL Standard
postman-collection-transformer
Perform rapid conversation and validation of JSON structure between Postman Collection Format v1 and v2
npm install postman-code-generators
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
996 Stars
1,561 Commits
351 Forks
34 Watching
59 Branches
77 Contributors
Updated on 20 Nov 2024
Minified
Minified + Gzipped
JavaScript (99.24%)
Shell (0.73%)
PHP (0.03%)
Cumulative downloads
Total Downloads
Last day
-3.3%
3,222
Compared to previous day
Last week
4.4%
17,818
Compared to previous week
Last month
27.3%
94,365
Compared to previous month
Last year
208.8%
1,231,666
Compared to previous year
Manage all of your organization's APIs in Postman, with the industry's most complete API development environment.
Supercharge your API workflow.
Modern software is built on APIs. Postman helps you develop APIs faster.
This module converts a Postman SDK Request Object into a code snippet of chosen language.
Every code generator has two identifiers: language
and variant
.
language
of a code generator is the programming language in which the code snippet is generated.variant
of a code generator is the methodology or the underlying library used by the language to send requests.List of supported code generators:
Language | Variant |
---|---|
C | libcurl |
C# | HttpClient |
C# | RestSharp |
cURL | cURL |
Dart | http |
Go | Native |
HTTP | HTTP |
Java | OkHttp |
Java | Unirest |
JavaScript | Fetch |
JavaScript | jQuery |
JavaScript | XHR |
Kotlin | OkHttp |
NodeJs | Axios |
NodeJs | Native |
NodeJs | Request |
NodeJs | Unirest |
Objective-C | NSURLSession |
OCaml | Cohttp |
PHP | cURL |
PHP | Guzzle |
PHP | pecl_http |
PHP | HTTP_Request2 |
PowerShell | RestMethod |
Python | http.client |
Python | Requests |
R | httr |
R | RCurl |
Rust | Reqwest |
Ruby | Net:HTTP |
Shell | Httpie |
Shell | wget |
Swift | URLSession |
To install postman-code-generators as your dependency
1$ npm install postman-code-generators
To get a copy on your local machine
1$ git clone https://github.com/postmanlabs/postman-code-generators.git
To run any of the postman-code-generators, ensure that you have NodeJS >= v8. A copy of the NodeJS installable can be downloaded from https://nodejs.org/en/download/package-manager.
There are three functions that are exposed in postman-code-generators: getLanguageList, getOptions, and convert.
This function returns a list of supported code generators.
1var codegen = require('postman-code-generators'), // require postman-code-generators in your project 2 supportedCodegens = codegen.getLanguageList(); 3 console.log(supportedCodegens); 4 // output: 5 // [ 6 // { 7 // key: 'nodejs', 8 // label: 'NodeJs', 9 // syntax_mode: 'javascript', 10 // variant: [ 11 // { 12 // key: 'Requests' 13 // }, 14 // { 15 // key: 'Native' 16 // }, 17 // { 18 // key: 'Unirest' 19 // } 20 // ] 21 // }, 22 // ... 23 // ]
This function takes in three parameters and returns a callback with error and supported options of that code generator.
language
- language key from the language list returned from getLanguageList functionvariant
- variant key provided by getLanguageList functioncallback
- callback function with first parameter as error and second parameter as array of options supported by the codegen.A typical option has the following properties:
name
- Display nameid
- unique ID of the optiontype
- Data type of the option. (Allowed data types: boolean
, enum
, positiveInteger
)default
- Default value. The value that is used if this option is not specified while creating code snippetdescription
- User friendly description.1var codegen = require('postman-code-generators'), // require postman-code-generators in your project 2 language = 'nodejs', 3 variant = 'Request'; 4 5 codegen.getOptions(language, variant, function (error, options) { 6 if (error) { 7 // handle error 8 } 9 console.log(options); 10 }); 11// output: 12// [ 13// { 14// name: 'Set indentation count', 15// id: 'indentCount', 16// type: 'positiveInteger', 17// default: 2, 18// description: 'Set the number of indentation characters to add per code level' 19// }, 20// { 21// name: 'Set indentation type', 22// id: 'indentType', 23// type: 'enum', 24// availableOptions: ['Tab', 'Space'], 25// default: 'Space', 26// description: 'Select the character used to indent lines of code' 27// }, 28// ... 29// ];
This function takes in five parameters and returns a callback with error and generated code snippet
language
- lang key from the language list returned from getLanguageList functionvariant
- variant key provided by getLanguageList functionrequest
- Postman-SDK Request Objectoptions
- Options that can be used to configure generated code snippet. Defaults will be used for the unspecified attributescallback
- callback function with first parameter as error and second parameter as string for code snippet1var codegen = require('postman-code-generators'), // require postman-code-generators in your project 2 sdk = require('postman-collection'), // require postman-collection in your project 3 request = new sdk.Request('https://www.google.com'), //using postman sdk to create request 4 language = 'nodejs', 5 variant = 'request', 6 options = { 7 indentCount: 3, 8 indentType: 'Space', 9 trimRequestBody: true, 10 followRedirect: true 11 }; 12codegen.convert(language, variant, request, options, function(error, snippet) { 13 if (error) { 14 // handle error 15 } 16 // handle snippet 17});
This command will install all the dependencies in production mode.
1$ npm install;
To install dev dependencies also for all codegens run:
1$ npm run deepinstall dev;
To run common repo test as well as tests (common structure test + individual codegen tests) for all the codegens
1$ npm test;
To run structure and individual tests on a single codegen
1$ npm test <codegen-name>; 2# Here "codege-name" is the folder name of the codegen inside codegens folder
To create zipped package of all codegens
1$ npm run package;
Note: The zipped package is created inside each codegen's folder.
To create zipped package of a single codegen
1$ npm run package <codegen-name>
Please take a moment to read our contributing guide to learn about our development process. Open an issue first to discuss potential changes/additions.
This software is licensed under Apache-2.0. Copyright Postman, Inc. See the LICENSE.md file for more information.
No vulnerabilities found.
Reason
20 commit(s) and 4 issue activity found in the last 90 days -- score normalized to 10
Reason
all changesets reviewed
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 1
Details
Reason
dangerous workflow patterns detected
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
45 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More