A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/postmanlabs/postman-code-generators below:

postmanlabs/postman-code-generators: Common repository for all code generators shipped with Postman


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.

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

$ npm install postman-code-generators

To get a copy on your local machine

$ 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.

Using postman-code-generators as a Library

There are three functions that are exposed in postman-code-generators: getLanguageList, getOptions, and convert.

This function returns a list of supported code generators.

var codegen = require('postman-code-generators'), // require postman-code-generators in your project
    supportedCodegens = codegen.getLanguageList();
    console.log(supportedCodegens);
    // output:
    // [
    //   {
    //     key: 'nodejs',
    //     label: 'NodeJs',
    //     syntax_mode: 'javascript',
    //     variant: [
    //       {
    //         key: 'Requests'
    //       },
    //       {
    //         key: 'Native'
    //       },
    //       {
    //         key: 'Unirest'
    //       }
    //     ]
    //   },
    //   ...
    // ]

This function takes in three parameters and returns a callback with error and supported options of that code generator.

A typical option has the following properties:

var codegen = require('postman-code-generators'), // require postman-code-generators in your project
    language = 'nodejs',
    variant = 'Request';

    codegen.getOptions(language, variant, function (error, options) {
      if (error) {
        // handle error
      }
      console.log(options);
    });
// output: 
//     [
//     {
//       name: 'Set indentation count',
//       id: 'indentCount',
//       type: 'positiveInteger',
//       default: 2,
//       description: 'Set the number of indentation characters to add per code level'
//     },
//     {
//       name: 'Set indentation type',
//       id: 'indentType',
//       type: 'enum',
//       availableOptions: ['Tab', 'Space'],
//       default: 'Space',
//       description: 'Select the character used to indent lines of code'
//     },
//     ...
//   ];

This function takes in five parameters and returns a callback with error and generated code snippet

var codegen = require('postman-code-generators'), // require postman-code-generators in your project
    sdk = require('postman-collection'), // require postman-collection in your project
    request = new sdk.Request('https://www.google.com'),  //using postman sdk to create request 
    language = 'nodejs',
    variant = 'request',
    options = {
        indentCount: 3,
        indentType: 'Space',
        trimRequestBody: true,
        followRedirect: true
    };
codegen.convert(language, variant, request, options, function(error, snippet) {
    if (error) {
        //  handle error
    }
    //  handle snippet
});

This command will install all the dependencies in production mode.

To install dev dependencies also for all codegens run:

$ npm run deepinstall dev; 

To run common repo test as well as tests (common structure test + individual codegen tests) for all the codegens

To run structure and individual tests on a single codegen

$ npm test <codegen-name>;
# Here "codege-name" is the folder name of the codegen inside codegens folder

To create zipped package of all codegens

Note: The zipped package is created inside each codegen's folder.

To create zipped package of a single codegen

$ 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.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4