Skip to content

Introduction

http-request-codegen generates HTTP request code snippets for different implementations. It's perfect if you want to include examples documenting APIs. Supports the following features:

  • Request parameters values randomization using multiples strategies:
    • Random values from iterables and callables.
    • Random values from data types.
    • Random values from Faker providers.
    • Randomization using seeds and localization.
  • Request headers customization.
  • Request optional arguments by implementation.
  • Custom line wrapping.
  • Custom indentation.
  • Custom quotation characters.
  • Rendering in one line.

Remember

This is not a greater level API across multiple HTTP request libraries, but it is written so that you can generate the most common types of HTTP requests regardless of the implementation.

Installation

pip install http-request-codegen
pipenv install http-request-codegen
git clone https://github.com/mondeja/http-request-codegen.git --depth=1
cd http-request-codegen
python setup.py install
git clone https://github.com/mondeja/http-request-codegen.git
cd http-request-codegen
pip install -e .[dev]

Demo

import fake_module

from http_request_codegen import generate_http_request_code

generate_http_request_code(
    language='javascript',
    impl='fetch',
    method='GET',
    url='https://github.com/mondeja/http-request-codegen',
    headers={
        'Content-Type': 'application/json',
        'Accept-Language': '*'
    },
    seed=2032,
    parameters=[
        {
            'name': 'fixed-value',
            'value': 3
        },
        {
            'name': 'dinamic-value-by-iterable',
            'value': [1, 2, 3]  # same as 'values': [1, 2, 3]
        },
        {
            'name': 'dinamic-value-by-function',
            'value': fake_module.integers_from_1_to_10
        },

        # Parameter value randomization
        {
            'name': 'random-values-by-iterable',
            'values': ['foo', 'bar', 'baz']
        },
        {
            'name': 'random-values-by-function',
            'values': fake_module.integers_from_1_to_10
        },
        {
            'name': 'random-values-by-function-path',
            'values': 'fake_module::integers_from_1_to_10'
        },
        {
            'name': 'random-value-by-faker-provider-function-path',
            'faker': 'faker.providers.job::job'
        },
        {
            'name': 'random-string',  # by default: random word
            'type': 'str'
        },
        {
            'name': 'random-integer',
            'type': 'int',
        },
        {
            'name': 'random-integer-in-range',
            'type': int,  # You can use Python types also
            'min': 2,
            'max': 5,
        },
        {
            'name': 'random-float',
            'type': 'number',  # You can use some type aliases also
        },
        {
            'name': 'random-rounded-float-in-range',
            'type': float,
            'min': 1.555,
            'max': 2.555,
            'round': 3
        },
        {
            'name': 'random-boolean',
            'type': bool
        },
        {
            'name': 'random-boolean-nullable',
            'type': 'boolean',
            'null': True
        },
        {
            'name': 'random-type',
            'type': 'random'  # random type from availables
        },
        {
            'name': 'random-unique-identifier',
            'type': 'uuid'
        },
        {
            'name': 'random-id',  # positive integer
            'type': 'id'
        },

        # Parameter name randomization
        {
            'name': ['random-name-from-iterable',
                     'random-name-by-iterable'],
            'type': 'str',
        },
        {
            'name': fake_module.random_name_by_function,
            'type': 'random',
        },
    ]
)

This implementation will emulate browsers' fetch API by default. using Promises-like response processing.

If you want to simulate a NodeJS environment, pass the parameter setup as True and the next initialization snippet will be prepended to the generated code:

const fetch = require('node-fetch');

For ESM imports emulation, use setup='import fetch from \'node-fetch\';\n\n', thus the initialization snippet will be:

import fetch from 'node-fetch';

Of course, you can customize this initialization for other environments. For example, polyfill the API using whatwg as ESM module with setup='import \'whatwg-fetch\';\n\n':

import 'whatwg-fetch';
fetch(
  'https://github.com/mondeja/http-request-codegen?fixed-value=3&dinamic-value'
  + '-by-iterable=1&dinamic-value-by-function=0&random-values-by-iterable=foo&'
  + 'random-values-by-function=0&random-values-by-function-path=0&random-value'
  + '-by-faker-provider-function-path=Analytical+chemist&random-string=party&r'
  + 'andom-integer=-56649&random-integer-in-range=2&random-float=42960.2871424'
  + '83445&random-rounded-float-in-range=2.383&random-boolean=true&random-bool'
  + 'ean-nullable=true&random-type=religious&random-unique-identifier=ecccd9c2'
  + 'a80c4e43a90459d0c91756cc&random-id=4444&random-name-from-iterable=main&ra'
  + 'ndom-name-from-function=camera',
  {
    headers: {
      'Content-Type': 'application/json',
      'Accept-Language': '*'
    }
  }
).then(function(response) {
  console.log(response);
}).catch(function(err) {
  console.error('Error:', err);
});
import fake_module

from http_request_codegen import generate_http_request_code

generate_http_request_code(
    language='javascript',
    impl='fetch',
    method='POST',
    url='https://github.com/mondeja/http-request-codegen',
    headers={
        'Accept-Language': '*',
        'Accept-Charset': 'utf-8'
    },
    seed=2032,
    parameters=[
        {
            'name': 'fixed-value',
            'value': 3
        },
        {
            'name': 'dinamic-value-by-iterable',
            'value': [1, 2, 3]  # same as 'values': [1, 2, 3]
        },
        {
            'name': 'dinamic-value-by-function',
            'value': fake_module.integers_from_1_to_10
        },

        # Parameter value randomization
        {
            'name': 'random-values-by-iterable',
            'values': ['foo', 'bar', 'baz']
        },
        {
            'name': 'random-values-by-function',
            'values': fake_module.integers_from_1_to_10
        },
        {
            'name': 'random-values-by-function-path',
            'values': 'fake_module::integers_from_1_to_10'
        },
        {
            'name': 'random-value-by-faker-provider-function-path',
            'faker': 'faker.providers.job::job'
        },
        {
            'name': 'random-string',  # by default: random word
            'type': 'str'
        },
        {
            'name': 'random-integer',
            'type': 'int',
        },
        {
            'name': 'random-integer-in-range',
            'type': int,  # You can use Python types also
            'min': 2,
            'max': 5,
        },
        {
            'name': 'random-float',
            'type': 'number',  # You can use some type aliases also
        },
        {
            'name': 'random-rounded-float-in-range',
            'type': float,
            'min': 1.555,
            'max': 2.555,
            'round': 3
        },
        {
            'name': 'random-boolean',
            'type': bool
        },
        {
            'name': 'random-boolean-nullable',
            'type': 'boolean',
            'null': True
        },
        {
            'name': 'random-type',
            'type': 'random'  # random type from availables
        },
        {
            'name': 'random-unique-identifier',
            'type': 'uuid'
        },
        {
            'name': 'random-id',  # positive integer
            'type': 'id'
        },

        # Parameter name randomization
        {
            'name': ['random-name-from-iterable',
                     'random-name-by-iterable'],
            'type': 'str',
        },
        {
            'name': fake_module.random_name_by_function,
            'type': 'random',
        },
    ]
)
const fetch = require('node-fetch');

fetch(
  'https://github.com/mondeja/http-request-codegen',
  {  
    method: 'POST',
    body: new URLSearchParams({
      'fixed-value': '3',
      'dinamic-value-by-iterable': '1',
      'dinamic-value-by-function': '0',
      'random-values-by-iterable': 'foo',
      'random-values-by-function': '0',
      'random-values-by-function-path': '0',
      'random-value-by-faker-provider-function-path': 'Psychologist, education'
                                                      + 'al',
      'random-string': 'drive',
      'random-integer': '-56649',
      'random-integer-in-range': '2',
      'random-float': '42960.287142483445',
      'random-rounded-float-in-range': '2.383',
      'random-boolean': 'true',
      'random-boolean-nullable': 'true',
      'random-type': 'control',
      'random-unique-identifier': '904413fe28cc4fc0a9b6f671fde19ded',
      'random-id': '4444',
      'random-name-from-iterable': 'people',
      'random-name-from-function': 'realize'
    }),
    headers: {
      'Accept-Language': '*',
      'Accept-Charset': 'utf-8'
    }
  }
).then(function(response) {
  console.log(response);
}).catch(function(err) {
  console.error('Error:', err);
});
from http_request_codegen import generate_http_request_code

generate_http_request_code(
    language='javascript',
    impl='fetch',
    method='POST',
    url='https://github.com/mondeja/http-request-codegen',
    headers={
        'Accept-Language': '*',
        'Accept-Charset': 'utf-8'
    },
    seed=2032,
    files={
        'fixed-filepath': '/tmp/foo.txt',
        'random-filepath': None,
        'fixed-filepath-content-type': (
            '/tmp/bar.csv',
            'text/csv'
        ),
        'fixed-filepath-ct-header': (
            '/tmp/bar.json',
            'application/json',
            {'Accept-Charset': 'utf-8'}
        ),
        'random-filepath-content-type': (
            None,
            'text/plain'
        ),
        'random-filepath-ct-header': (
            None,
            'text/csv',
            {'Accept-Charset': 'utf-8'}
        )
    }
)
const fs = require('fs');

const fetch = require('node-fetch');
const FormData = require('form-data');

const formData = new FormData();
formData.append(
  'fixed-filepath',
  fs.createReadStream('/tmp/foo.txt'),
  {
    filename: 'foo.txt'
  }
);
formData.append(
  'random-filepath',
  fs.createReadStream('/simply/stock.doc'),
  {
    filename: 'stock.doc'
  }
);
formData.append(
  'fixed-filepath-content-type',
  fs.createReadStream('/tmp/bar.csv'),
  {
    filename: 'bar.csv',
    contentType: 'text/csv'
  }
);
formData.append(
  'fixed-filepath-ct-header',
  fs.createReadStream('/tmp/bar.json'),
  {
    filename: 'bar.json',
    contentType: 'application/json'
  }
);
formData.append(
  'random-filepath-content-type',
  fs.createReadStream('/civil/young.jpg'),
  {
    filename: 'young.jpg',
    contentType: 'text/plain'
  }
);
formData.append(
  'random-filepath-ct-header',
  fs.createReadStream('/first/start.tiff'),
  {
    filename: 'start.tiff',
    contentType: 'text/csv'
  }
);

fetch(
  'https://github.com/mondeja/http-request-codegen',
  {  
    method: 'POST',
    body: formData,
    headers: {
      'Accept-Language': '*',
      'Accept-Charset': 'utf-8'
    }
  }
).then(function(response) {
  console.log(response);
}).catch(function(err) {
  console.error('Error:', err);
});
import fake_module

from http_request_codegen import generate_http_request_code

generate_http_request_code(
    language='javascript',
    impl='fetch',
    method='POST',
    url='https://github.com/mondeja/http-request-codegen',
    headers={
        'Content-Type': 'application/json'
    },
    seed=2032,
    parameters=[
        {
            'name': 'fixed-value',
            'value': 3
        },
        {
            'name': 'dinamic-value-by-iterable',
            'value': [1, 2, 3]  # same as 'values': [1, 2, 3]
        },
        {
            'name': 'dinamic-value-by-function',
            'value': fake_module.integers_from_1_to_10
        },

        # Parameter value randomization
        {
            'name': 'random-values-by-iterable',
            'values': ['foo', 'bar', 'baz']
        },
        {
            'name': 'random-values-by-function',
            'values': fake_module.integers_from_1_to_10
        },
        {
            'name': 'random-values-by-function-path',
            'values': 'fake_module::integers_from_1_to_10'
        },
        {
            'name': 'random-value-by-faker-provider-function-path',
            'faker': 'faker.providers.job::job'
        },
        {
            'name': 'random-string',  # by default: random word
            'type': 'str'
        },
        {
            'name': 'random-integer',
            'type': 'int',
        },
        {
            'name': 'random-integer-in-range',
            'type': int,  # You can use Python types also
            'min': 2,
            'max': 5,
        },
        {
            'name': 'random-float',
            'type': 'number',  # You can use some type aliases also
        },
        {
            'name': 'random-rounded-float-in-range',
            'type': float,
            'min': 1.555,
            'max': 2.555,
            'round': 3
        },
        {
            'name': 'random-boolean',
            'type': bool
        },
        {
            'name': 'random-boolean-nullable',
            'type': 'boolean',
            'null': True
        },
        {
            'name': 'random-type',
            'type': 'random'  # random type from availables
        },
        {
            'name': 'random-unique-identifier',
            'type': 'uuid'
        },
        {
            'name': 'random-id',  # positive integer
            'type': 'id'
        },

        # Parameter name randomization
        {
            'name': ['random-name-from-iterable',
                     'random-name-by-iterable'],
            'type': 'str',
        },
        {
            'name': fake_module.random_name_by_function,
            'type': 'random',
        },
    ]
)
const fetch = require('node-fetch');

fetch(
  'https://github.com/mondeja/http-request-codegen',
  {  
    method: 'POST',
    body: JSON.stringify({
      'fixed-value': '3',
      'dinamic-value-by-iterable': '1',
      'dinamic-value-by-function': '0',
      'random-values-by-iterable': 'foo',
      'random-values-by-function': '0',
      'random-values-by-function-path': '0',
      'random-value-by-faker-provider-function-path': 'Financial controller',
      'random-string': 'stage',
      'random-integer': '-56649',
      'random-integer-in-range': '2',
      'random-float': '42960.287142483445',
      'random-rounded-float-in-range': '2.383',
      'random-boolean': 'true',
      'random-boolean-nullable': 'true',
      'random-type': 'speech',
      'random-unique-identifier': 'bdf7385745384a46ab83c8dabe1eee42',
      'random-id': '4444',
      'random-name-from-iterable': 'Republican',
      'random-name-from-function': 'pay'
    }),
    headers: {
      'Content-Type': 'application/json'
    }
  }
).then(function(response) {
  console.log(response);
}).catch(function(err) {
  console.error('Error:', err);
});
from http_request_codegen import generate_http_request_code

generate_http_request_code(
    language='javascript',
    impl='fetch',
    method='POST',
    url='https://github.com/mondeja/http-request-codegen',
    headers={
        'Content-Type': 'text/plain'
    },
    seed=2032,
    parameters=[
        {
            'name': 'random-values-by-iterable',
            'values': ['foo', 'bar', 'baz']
        }
    ]
)
const fetch = require('node-fetch');

fetch(
  'https://github.com/mondeja/http-request-codegen',
  {  
    method: 'POST',
    body: 'foo',
    headers: {
      'Content-Type': 'text/plain'
    }
  }
).then(function(response) {
  console.log(response);
}).catch(function(err) {
  console.error('Error:', err);
});
import fake_module

from http_request_codegen import generate_http_request_code

generate_http_request_code(
    language='python',
    impl='requests',
    method='GET',
    url='https://github.com/mondeja/http-request-codegen',
    headers={
        'Content-Type': 'application/json',
        'Accept-Language': '*'
    },
    seed=2032,
    parameters=[
        {
            'name': 'fixed-value',
            'value': 3
        },
        {
            'name': 'dinamic-value-by-iterable',
            'value': [1, 2, 3]  # same as 'values': [1, 2, 3]
        },
        {
            'name': 'dinamic-value-by-function',
            'value': fake_module.integers_from_1_to_10
        },

        # Parameter value randomization
        {
            'name': 'random-values-by-iterable',
            'values': ['foo', 'bar', 'baz']
        },
        {
            'name': 'random-values-by-function',
            'values': fake_module.integers_from_1_to_10
        },
        {
            'name': 'random-values-by-function-path',
            'values': 'fake_module::integers_from_1_to_10'
        },
        {
            'name': 'random-value-by-faker-provider-function-path',
            'faker': 'faker.providers.job::job'
        },
        {
            'name': 'random-string',  # by default: random word
            'type': 'str'
        },
        {
            'name': 'random-integer',
            'type': 'int',
        },
        {
            'name': 'random-integer-in-range',
            'type': int,  # You can use Python types also
            'min': 2,
            'max': 5,
        },
        {
            'name': 'random-float',
            'type': 'number',  # You can use some type aliases also
        },
        {
            'name': 'random-rounded-float-in-range',
            'type': float,
            'min': 1.555,
            'max': 2.555,
            'round': 3
        },
        {
            'name': 'random-boolean',
            'type': bool
        },
        {
            'name': 'random-boolean-nullable',
            'type': 'boolean',
            'null': True
        },
        {
            'name': 'random-type',
            'type': 'random'  # random type from availables
        },
        {
            'name': 'random-unique-identifier',
            'type': 'uuid'
        },
        {
            'name': 'random-id',  # positive integer
            'type': 'id'
        },

        # Parameter name randomization
        {
            'name': ['random-name-from-iterable',
                     'random-name-by-iterable'],
            'type': 'str',
        },
        {
            'name': fake_module.random_name_by_function,
            'type': 'random',
        },
    ]
)

Parameters are passed using requests.get function params parameter, not by appending ?foo=bar&... to the URL. If you want this behaviour, build the passed URL using lazy_name_by_parameter and lazy_value_by_parameter functions instead of use the parameters argument.

If you want to import more modules in the initialization snippet, keep in mind that you must provide import requests line also in the setup argument. For example, setup='import requests\nimport foo\n\n' will render as:

import requests
import foo

requests.get('<url>'...
import requests

req = requests.get(
    'https://github.com/mondeja/http-request-codegen',
    params={
        'fixed-value': '3',
        'dinamic-value-by-iterable': '1',
        'dinamic-value-by-function': '0',
        'random-values-by-iterable': 'foo',
        'random-values-by-function': '0',
        'random-values-by-function-path': '0',
        'random-value-by-faker-provider-function-path': 'Engineer, energy',
        'random-string': 'bed',
        'random-integer': '-56649',
        'random-integer-in-range': '2',
        'random-float': '42960.287142483445',
        'random-rounded-float-in-range': '2.383',
        'random-boolean': 'true',
        'random-boolean-nullable': 'true',
        'random-type': 'political',
        'random-unique-identifier': 'a19011bf47d04d488b2e14dc23b8deff',
        'random-id': '4444',
        'random-name-from-iterable': 'develop',
        'random-name-from-function': 'stuff'
    },
    headers={
        'Content-Type': 'application/json',
        'Accept-Language': '*'
    }
)
import fake_module

from http_request_codegen import generate_http_request_code

generate_http_request_code(
    language='python',
    impl='requests',
    method='POST',
    url='https://github.com/mondeja/http-request-codegen',
    headers={
        'Accept-Language': '*',
        'Accept-Charset': 'utf-8'
    },
    seed=2032,
    parameters=[
        {
            'name': 'fixed-value',
            'value': 3
        },
        {
            'name': 'dinamic-value-by-iterable',
            'value': [1, 2, 3]  # same as 'values': [1, 2, 3]
        },
        {
            'name': 'dinamic-value-by-function',
            'value': fake_module.integers_from_1_to_10
        },

        # Parameter value randomization
        {
            'name': 'random-values-by-iterable',
            'values': ['foo', 'bar', 'baz']
        },
        {
            'name': 'random-values-by-function',
            'values': fake_module.integers_from_1_to_10
        },
        {
            'name': 'random-values-by-function-path',
            'values': 'fake_module::integers_from_1_to_10'
        },
        {
            'name': 'random-value-by-faker-provider-function-path',
            'faker': 'faker.providers.job::job'
        },
        {
            'name': 'random-string',  # by default: random word
            'type': 'str'
        },
        {
            'name': 'random-integer',
            'type': 'int',
        },
        {
            'name': 'random-integer-in-range',
            'type': int,  # You can use Python types also
            'min': 2,
            'max': 5,
        },
        {
            'name': 'random-float',
            'type': 'number',  # You can use some type aliases also
        },
        {
            'name': 'random-rounded-float-in-range',
            'type': float,
            'min': 1.555,
            'max': 2.555,
            'round': 3
        },
        {
            'name': 'random-boolean',
            'type': bool
        },
        {
            'name': 'random-boolean-nullable',
            'type': 'boolean',
            'null': True
        },
        {
            'name': 'random-type',
            'type': 'random'  # random type from availables
        },
        {
            'name': 'random-unique-identifier',
            'type': 'uuid'
        },
        {
            'name': 'random-id',  # positive integer
            'type': 'id'
        },

        # Parameter name randomization
        {
            'name': ['random-name-from-iterable',
                     'random-name-by-iterable'],
            'type': 'str',
        },
        {
            'name': fake_module.random_name_by_function,
            'type': 'random',
        },
    ]
)
import requests

req = requests.post(
    'https://github.com/mondeja/http-request-codegen',
    data={
        'fixed-value': '3',
        'dinamic-value-by-iterable': '1',
        'dinamic-value-by-function': '0',
        'random-values-by-iterable': 'foo',
        'random-values-by-function': '0',
        'random-values-by-function-path': '0',
        'random-value-by-faker-provider-function-path': ('Community developmen'
                                                         't worker'),
        'random-string': 'health',
        'random-integer': '-56649',
        'random-integer-in-range': '2',
        'random-float': '42960.287142483445',
        'random-rounded-float-in-range': '2.383',
        'random-boolean': 'true',
        'random-boolean-nullable': 'true',
        'random-type': 'group',
        'random-unique-identifier': '22d6f1b7b2f743c598b01228758794ff',
        'random-id': '4444',
        'random-name-from-iterable': 'good',
        'random-name-from-function': 'decade'
    },
    headers={
        'Accept-Language': '*',
        'Accept-Charset': 'utf-8'
    }
)
from http_request_codegen import generate_http_request_code

generate_http_request_code(
    language='python',
    impl='requests',
    method='POST',
    url='https://github.com/mondeja/http-request-codegen',
    headers={
        'Accept-Language': '*',
        'Accept-Charset': 'utf-8'
    },
    seed=2032,
    files={
        'fixed-filepath': '/tmp/foo.txt',
        'random-filepath': None,
        'fixed-filepath-content-type': (
            '/tmp/bar.csv',
            'text/csv'
        ),
        'fixed-filepath-ct-header': (
            '/tmp/bar.json',
            'application/json',
            {'Accept-Charset': 'utf-8'}
        ),
        'random-filepath-content-type': (
            None,
            'text/plain'
        ),
        'random-filepath-ct-header': (
            None,
            'text/csv',
            {'Accept-Charset': 'utf-8'}
        )
    }
)
import requests

req = requests.post(
    'https://github.com/mondeja/http-request-codegen',
    files={
        'fixed-filepath': (
            '/tmp/foo.txt',
            open('/tmp/foo.txt', 'rb')
        ),
        'random-filepath': (
            '/right/case.webm',
            open('/right/case.webm', 'rb')
        ),
        'fixed-filepath-content-type': (
            '/tmp/bar.csv',
            open('/tmp/bar.csv', 'rb'),
            'text/csv'
        ),
        'fixed-filepath-ct-header': (
            '/tmp/bar.json',
            open('/tmp/bar.json', 'rb'),
            'application/json',
            {
                'Accept-Charset': 'utf-8'
            }
        ),
        'random-filepath-content-type': (
            '/child/natural.wav',
            open('/child/natural.wav', 'rb'),
            'text/plain'
        ),
        'random-filepath-ct-header': (
            '/statement/able.ppt',
            open('/statement/able.ppt', 'rb'),
            'text/csv',
            {
                'Accept-Charset': 'utf-8'
            }
        )
    },
    headers={
        'Accept-Language': '*',
        'Accept-Charset': 'utf-8'
    }
)
import fake_module

from http_request_codegen import generate_http_request_code

generate_http_request_code(
    language='python',
    impl='requests',
    method='POST',
    url='https://github.com/mondeja/http-request-codegen',
    headers={
        'Content-Type': 'application/json'
    },
    seed=2032,
    parameters=[
        {
            'name': 'fixed-value',
            'value': 3
        },
        {
            'name': 'dinamic-value-by-iterable',
            'value': [1, 2, 3]  # same as 'values': [1, 2, 3]
        },
        {
            'name': 'dinamic-value-by-function',
            'value': fake_module.integers_from_1_to_10
        },

        # Parameter value randomization
        {
            'name': 'random-values-by-iterable',
            'values': ['foo', 'bar', 'baz']
        },
        {
            'name': 'random-values-by-function',
            'values': fake_module.integers_from_1_to_10
        },
        {
            'name': 'random-values-by-function-path',
            'values': 'fake_module::integers_from_1_to_10'
        },
        {
            'name': 'random-value-by-faker-provider-function-path',
            'faker': 'faker.providers.job::job'
        },
        {
            'name': 'random-string',  # by default: random word
            'type': 'str'
        },
        {
            'name': 'random-integer',
            'type': 'int',
        },
        {
            'name': 'random-integer-in-range',
            'type': int,  # You can use Python types also
            'min': 2,
            'max': 5,
        },
        {
            'name': 'random-float',
            'type': 'number',  # You can use some type aliases also
        },
        {
            'name': 'random-rounded-float-in-range',
            'type': float,
            'min': 1.555,
            'max': 2.555,
            'round': 3
        },
        {
            'name': 'random-boolean',
            'type': bool
        },
        {
            'name': 'random-boolean-nullable',
            'type': 'boolean',
            'null': True
        },
        {
            'name': 'random-type',
            'type': 'random'  # random type from availables
        },
        {
            'name': 'random-unique-identifier',
            'type': 'uuid'
        },
        {
            'name': 'random-id',  # positive integer
            'type': 'id'
        },

        # Parameter name randomization
        {
            'name': ['random-name-from-iterable',
                     'random-name-by-iterable'],
            'type': 'str',
        },
        {
            'name': fake_module.random_name_by_function,
            'type': 'random',
        },
    ]
)
import requests

req = requests.post(
    'https://github.com/mondeja/http-request-codegen',
    json={
        'fixed-value': 3,
        'dinamic-value-by-iterable': '1',
        'dinamic-value-by-function': '0',
        'random-values-by-iterable': 'foo',
        'random-values-by-function': '0',
        'random-values-by-function-path': '0',
        'random-value-by-faker-provider-function-path': 'Pharmacologist',
        'random-string': 'according',
        'random-integer': '-56649',
        'random-integer-in-range': '2',
        'random-float': '42960.287142483445',
        'random-rounded-float-in-range': '2.383',
        'random-boolean': 'true',
        'random-boolean-nullable': 'true',
        'random-type': 'recent',
        'random-unique-identifier': '95d9e7b38076410784b1427d964a5334',
        'random-id': '4444',
        'random-name-from-iterable': 'society',
        'random-name-from-function': 'above'
    },
    headers={
        'Content-Type': 'application/json'
    }
)
from http_request_codegen import generate_http_request_code

generate_http_request_code(
    language='python',
    impl='requests',
    method='POST',
    url='https://github.com/mondeja/http-request-codegen',
    headers={
        'Content-Type': 'text/plain'
    },
    seed=2032,
    parameters=[
        {
            'name': 'random-values-by-iterable',
            'values': ['foo', 'bar', 'baz']
        }
    ]
)
import requests

req = requests.post(
    'https://github.com/mondeja/http-request-codegen',
    data='foo',
    headers={
        'Content-Type': 'text/plain'
    }
)
import fake_module

from http_request_codegen import generate_http_request_code

generate_http_request_code(
    language='bash',
    impl='curl',
    method='GET',
    url='https://github.com/mondeja/http-request-codegen',
    headers={
        'Content-Type': 'application/json',
        'Accept-Language': '*'
    },
    seed=2032,
    parameters=[
        {
            'name': 'fixed-value',
            'value': 3
        },
        {
            'name': 'dinamic-value-by-iterable',
            'value': [1, 2, 3]  # same as 'values': [1, 2, 3]
        },
        {
            'name': 'dinamic-value-by-function',
            'value': fake_module.integers_from_1_to_10
        },

        # Parameter value randomization
        {
            'name': 'random-values-by-iterable',
            'values': ['foo', 'bar', 'baz']
        },
        {
            'name': 'random-values-by-function',
            'values': fake_module.integers_from_1_to_10
        },
        {
            'name': 'random-values-by-function-path',
            'values': 'fake_module::integers_from_1_to_10'
        },
        {
            'name': 'random-value-by-faker-provider-function-path',
            'faker': 'faker.providers.job::job'
        },
        {
            'name': 'random-string',  # by default: random word
            'type': 'str'
        },
        {
            'name': 'random-integer',
            'type': 'int',
        },
        {
            'name': 'random-integer-in-range',
            'type': int,  # You can use Python types also
            'min': 2,
            'max': 5,
        },
        {
            'name': 'random-float',
            'type': 'number',  # You can use some type aliases also
        },
        {
            'name': 'random-rounded-float-in-range',
            'type': float,
            'min': 1.555,
            'max': 2.555,
            'round': 3
        },
        {
            'name': 'random-boolean',
            'type': bool
        },
        {
            'name': 'random-boolean-nullable',
            'type': 'boolean',
            'null': True
        },
        {
            'name': 'random-type',
            'type': 'random'  # random type from availables
        },
        {
            'name': 'random-unique-identifier',
            'type': 'uuid'
        },
        {
            'name': 'random-id',  # positive integer
            'type': 'id'
        },

        # Parameter name randomization
        {
            'name': ['random-name-from-iterable',
                     'random-name-by-iterable'],
            'type': 'str',
        },
        {
            'name': fake_module.random_name_by_function,
            'type': 'random',
        },
    ]
)

Pass extra options to 'curl' command in kwargs parameter. For example, to save the response in a file, pass kwargs={'-o': 'filename.ext'}:

curl -o "filename.ext"
curl \
    -d 'fixed-value=3&dinamic-value-by-iterable=1&dinamic-value-by-function=0&random-values-by-iterable=foo&random-values-by-function=0&random-values-by-function-path=0&random-value-by-faker-provider-function-path=Advice+worker&random-string=country&random-integer=-56649&random-integer-in-range=2&random-float=42960.287142483445&random-rounded-float-in-range=2.383&random-boolean=true&random-boolean-nullable=true&random-type=them&random-unique-identifier=34f35b280ca744409c8fe404c28705e7&random-id=4444&random-name-from-iterable=stage&random-name-from-function=develop' \
    -H 'Content-Type: application/json' \
    -H 'Accept-Language: *' \
    https://github.com/mondeja/http-request-codegen
import fake_module

from http_request_codegen import generate_http_request_code

generate_http_request_code(
    language='bash',
    impl='curl',
    method='POST',
    url='https://github.com/mondeja/http-request-codegen',
    headers={
        'Accept-Language': '*',
        'Accept-Charset': 'utf-8'
    },
    seed=2032,
    parameters=[
        {
            'name': 'fixed-value',
            'value': 3
        },
        {
            'name': 'dinamic-value-by-iterable',
            'value': [1, 2, 3]  # same as 'values': [1, 2, 3]
        },
        {
            'name': 'dinamic-value-by-function',
            'value': fake_module.integers_from_1_to_10
        },

        # Parameter value randomization
        {
            'name': 'random-values-by-iterable',
            'values': ['foo', 'bar', 'baz']
        },
        {
            'name': 'random-values-by-function',
            'values': fake_module.integers_from_1_to_10
        },
        {
            'name': 'random-values-by-function-path',
            'values': 'fake_module::integers_from_1_to_10'
        },
        {
            'name': 'random-value-by-faker-provider-function-path',
            'faker': 'faker.providers.job::job'
        },
        {
            'name': 'random-string',  # by default: random word
            'type': 'str'
        },
        {
            'name': 'random-integer',
            'type': 'int',
        },
        {
            'name': 'random-integer-in-range',
            'type': int,  # You can use Python types also
            'min': 2,
            'max': 5,
        },
        {
            'name': 'random-float',
            'type': 'number',  # You can use some type aliases also
        },
        {
            'name': 'random-rounded-float-in-range',
            'type': float,
            'min': 1.555,
            'max': 2.555,
            'round': 3
        },
        {
            'name': 'random-boolean',
            'type': bool
        },
        {
            'name': 'random-boolean-nullable',
            'type': 'boolean',
            'null': True
        },
        {
            'name': 'random-type',
            'type': 'random'  # random type from availables
        },
        {
            'name': 'random-unique-identifier',
            'type': 'uuid'
        },
        {
            'name': 'random-id',  # positive integer
            'type': 'id'
        },

        # Parameter name randomization
        {
            'name': ['random-name-from-iterable',
                     'random-name-by-iterable'],
            'type': 'str',
        },
        {
            'name': fake_module.random_name_by_function,
            'type': 'random',
        },
    ]
)
curl \
    -X 'POST' \
    -d 'fixed-value=3&dinamic-value-by-iterable=1&dinamic-value-by-function=0&random-values-by-iterable=foo&random-values-by-function=0&random-values-by-function-path=0&random-value-by-faker-provider-function-path=Technical+sales+engineer&random-string=cause&random-integer=-56649&random-integer-in-range=2&random-float=42960.287142483445&random-rounded-float-in-range=2.383&random-boolean=true&random-boolean-nullable=true&random-type=within&random-unique-identifier=bc3dd4fd3c6b4ecab7b9759b059f27d9&random-id=4444&random-name-from-iterable=watch&random-name-from-function=pull' \
    -H 'Accept-Language: *' \
    -H 'Accept-Charset: utf-8' \
    https://github.com/mondeja/http-request-codegen
from http_request_codegen import generate_http_request_code

generate_http_request_code(
    language='bash',
    impl='curl',
    method='POST',
    url='https://github.com/mondeja/http-request-codegen',
    headers={
        'Accept-Language': '*',
        'Accept-Charset': 'utf-8'
    },
    seed=2032,
    files={
        'fixed-filepath': '/tmp/foo.txt',
        'random-filepath': None,
        'fixed-filepath-content-type': (
            '/tmp/bar.csv',
            'text/csv'
        ),
        'fixed-filepath-ct-header': (
            '/tmp/bar.json',
            'application/json',
            {'Accept-Charset': 'utf-8'}
        ),
        'random-filepath-content-type': (
            None,
            'text/plain'
        ),
        'random-filepath-ct-header': (
            None,
            'text/csv',
            {'Accept-Charset': 'utf-8'}
        )
    }
)
curl \
    -X 'POST' \
    -F 'fixed-filepath=@/tmp/foo.txt' \
    -F 'random-filepath=@/hand/nor.gif' \
    -F 'fixed-filepath-content-type=@/tmp/bar.csv' \
    -F 'fixed-filepath-ct-header=@/tmp/bar.json' \
    -F 'random-filepath-content-type=@/move/bring.js' \
    -F 'random-filepath-ct-header=@/want/story.avi' \
    -H 'Accept-Language: *' \
    -H 'Accept-Charset: utf-8' \
    https://github.com/mondeja/http-request-codegen
import fake_module

from http_request_codegen import generate_http_request_code

generate_http_request_code(
    language='bash',
    impl='curl',
    method='POST',
    url='https://github.com/mondeja/http-request-codegen',
    headers={
        'Content-Type': 'application/json'
    },
    seed=2032,
    parameters=[
        {
            'name': 'fixed-value',
            'value': 3
        },
        {
            'name': 'dinamic-value-by-iterable',
            'value': [1, 2, 3]  # same as 'values': [1, 2, 3]
        },
        {
            'name': 'dinamic-value-by-function',
            'value': fake_module.integers_from_1_to_10
        },

        # Parameter value randomization
        {
            'name': 'random-values-by-iterable',
            'values': ['foo', 'bar', 'baz']
        },
        {
            'name': 'random-values-by-function',
            'values': fake_module.integers_from_1_to_10
        },
        {
            'name': 'random-values-by-function-path',
            'values': 'fake_module::integers_from_1_to_10'
        },
        {
            'name': 'random-value-by-faker-provider-function-path',
            'faker': 'faker.providers.job::job'
        },
        {
            'name': 'random-string',  # by default: random word
            'type': 'str'
        },
        {
            'name': 'random-integer',
            'type': 'int',
        },
        {
            'name': 'random-integer-in-range',
            'type': int,  # You can use Python types also
            'min': 2,
            'max': 5,
        },
        {
            'name': 'random-float',
            'type': 'number',  # You can use some type aliases also
        },
        {
            'name': 'random-rounded-float-in-range',
            'type': float,
            'min': 1.555,
            'max': 2.555,
            'round': 3
        },
        {
            'name': 'random-boolean',
            'type': bool
        },
        {
            'name': 'random-boolean-nullable',
            'type': 'boolean',
            'null': True
        },
        {
            'name': 'random-type',
            'type': 'random'  # random type from availables
        },
        {
            'name': 'random-unique-identifier',
            'type': 'uuid'
        },
        {
            'name': 'random-id',  # positive integer
            'type': 'id'
        },

        # Parameter name randomization
        {
            'name': ['random-name-from-iterable',
                     'random-name-by-iterable'],
            'type': 'str',
        },
        {
            'name': fake_module.random_name_by_function,
            'type': 'random',
        },
    ]
)
curl \
    -X 'POST' \
    -d 'fixed-value=3&dinamic-value-by-iterable=1&dinamic-value-by-function=0&random-values-by-iterable=foo&random-values-by-function=0&random-values-by-function-path=0&random-value-by-faker-provider-function-path=Engineer%2C+structural&random-string=cold&random-integer=-56649&random-integer-in-range=2&random-float=42960.287142483445&random-rounded-float-in-range=2.383&random-boolean=true&random-boolean-nullable=true&random-type=model&random-unique-identifier=c2da52529b124efb818e781f4a0434d5&random-id=4444&random-name-from-iterable=community&random-name-from-function=reason' \
    -H 'Content-Type: application/json' \
    https://github.com/mondeja/http-request-codegen
from http_request_codegen import generate_http_request_code

generate_http_request_code(
    language='bash',
    impl='curl',
    method='POST',
    url='https://github.com/mondeja/http-request-codegen',
    headers={
        'Content-Type': 'text/plain'
    },
    seed=2032,
    parameters=[
        {
            'name': 'random-values-by-iterable',
            'values': ['foo', 'bar', 'baz']
        }
    ]
)
curl \
    -X 'POST' \
    -d 'random-values-by-iterable=foo' \
    -H 'Content-Type: text/plain' \
    https://github.com/mondeja/http-request-codegen

Support

GET POST
Headers
Parameters
Parameters localization
Parameters seed
Custom indentation
Quotation character
One line rendering
Custom initialization
Custom teardown
Line wrapping
GET POST
Headers
Parameters
Parameters localization
Parameters seed
Custom indentation
Quotation character
One line rendering
Custom initialization
Custom teardown
Line wrapping
GET POST
Headers
Parameters
Parameters localization
Parameters seed
Custom indentation
Quotation character
One line rendering
Custom initialization
Custom teardown
Line wrapping