Generate client code for your API collections

You can generate client code for your API collections in Postman. Postman's Node.js code generator module converts a request into client code for your target language in conjunction with the Collection SDK.

The code generator takes a Collection SDK Request object and turns it into code to make the same request in a client app using the specified language and framework.

You can install the code generator library from npm or by cloning it from its repo.

To get started using the code generator module, check out the instructions for installation and usage in the project repo on GitHub.

You can also generate client code for a request or collection in Postman.

Using code generation programmatically

The following simplified code excerpt demonstrates using convert to build a client code snippet from a Request object with the Collection SDK, targeting Node.js:

var codegen = require('postman-code-generators'),
  sdk = require('postman-collection'),
  request = new sdk.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..

You can use the getOptions method to find config options for your target language:

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

codegen.getOptions(language, variant, function (error, options) {
  if (error) {
    // handle error

The getLanguageList method returns available languages your request client code can target:

var codegen = require('postman-code-generators'),
  supportedCodegens = codegen.getLanguageList();

Supported languages

The code generator module is an open-source project. If there is a language or framework you'd like to generate client code for, but it isn't provided, you can add it by contributing to the project. This lets other users access your contribution both in the repo and in Postman itself.

Next steps

If you're using Postman to work with client applications, you can also capture request data:

Last modified: 2023/10/04