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=8912,
    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=1&random-values-by-iterable=foo&'
  + 'random-values-by-function=1&random-values-by-function-path=1&random-value'
  + '-by-faker-provider-function-path=Clothing%2Ftextile+technologist&random-s'
  + 'tring=note&random-integer=-35820&random-integer-in-range=2&random-float=5'
  + '2337.46300132734&random-rounded-float-in-range=2.454&random-boolean=true&'
  + 'random-boolean-nullable=true&random-type=end&random-unique-identifier=4b0'
  + 'e5f63cf094469a7b5b97def22b134&random-id=14859&random-name-from-iterable=b'
  + 'ecome&random-name-from-function=design',
  {
    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=8912,
    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': '1',
      'random-values-by-iterable': 'foo',
      'random-values-by-function': '1',
      'random-values-by-function-path': '1',
      'random-value-by-faker-provider-function-path': 'Animator',
      'random-string': 'performance',
      'random-integer': '-35820',
      'random-integer-in-range': '2',
      'random-float': '52337.46300132734',
      'random-rounded-float-in-range': '2.454',
      'random-boolean': 'true',
      'random-boolean-nullable': 'true',
      'random-type': 'benefit',
      'random-unique-identifier': '06480aff2ffe4b00b326322e1f7e4940',
      'random-id': '14859',
      'random-name-from-iterable': 'quite',
      'random-name-from-function': 'pay'
    }),
    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=8912,
    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('/accept/offer.mp3'),
  {
    filename: 'offer.mp3'
  }
);
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('/rock/first.json'),
  {
    filename: 'first.json',
    contentType: 'text/plain'
  }
);
formData.append(
  'random-filepath-ct-header',
  fs.createReadStream('/join/your.mp4'),
  {
    filename: 'your.mp4',
    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=8912,
    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': '1',
      'random-values-by-iterable': 'foo',
      'random-values-by-function': '1',
      'random-values-by-function-path': '1',
      'random-value-by-faker-provider-function-path': 'Clothing/textile techno'
                                                      + 'logist',
      'random-string': 'truth',
      'random-integer': '-35820',
      'random-integer-in-range': '2',
      'random-float': '52337.46300132734',
      'random-rounded-float-in-range': '2.454',
      'random-boolean': 'true',
      'random-boolean-nullable': 'true',
      'random-type': 'world',
      'random-unique-identifier': '2b3d8972728c46438d953875fb662339',
      'random-id': '14859',
      'random-name-from-iterable': 'now',
      'random-name-from-function': 'couple'
    }),
    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=8912,
    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=8912,
    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': '1',
        'random-values-by-iterable': 'foo',
        'random-values-by-function': '1',
        'random-values-by-function-path': '1',
        'random-value-by-faker-provider-function-path': 'Physicist, medical',
        'random-string': 'argue',
        'random-integer': '-35820',
        'random-integer-in-range': '2',
        'random-float': '52337.46300132734',
        'random-rounded-float-in-range': '2.454',
        'random-boolean': 'true',
        'random-boolean-nullable': 'true',
        'random-type': 'son',
        'random-unique-identifier': '5f4883b9151a45d29f9e65f912b33977',
        'random-id': '14859',
        'random-name-from-iterable': 'there',
        'random-name-from-function': 'after'
    },
    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=8912,
    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': '1',
        'random-values-by-iterable': 'foo',
        'random-values-by-function': '1',
        'random-values-by-function-path': '1',
        'random-value-by-faker-provider-function-path': 'Sales executive',
        'random-string': 'name',
        'random-integer': '-35820',
        'random-integer-in-range': '2',
        'random-float': '52337.46300132734',
        'random-rounded-float-in-range': '2.454',
        'random-boolean': 'true',
        'random-boolean-nullable': 'true',
        'random-type': 'outside',
        'random-unique-identifier': '00a198ac8cf645d7b783671bbebd1e62',
        'random-id': '14859',
        'random-name-from-iterable': 'big',
        'random-name-from-function': 'scene'
    },
    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=8912,
    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': (
            '/pressure/answer.png',
            open('/pressure/answer.png', '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': (
            '/later/expect.html',
            open('/later/expect.html', 'rb'),
            'text/plain'
        ),
        'random-filepath-ct-header': (
            '/travel/put.wav',
            open('/travel/put.wav', '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=8912,
    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': '1',
        'random-values-by-iterable': 'foo',
        'random-values-by-function': '1',
        'random-values-by-function-path': '1',
        'random-value-by-faker-provider-function-path': 'Structural engineer',
        'random-string': 'future',
        'random-integer': '-35820',
        'random-integer-in-range': '2',
        'random-float': '52337.46300132734',
        'random-rounded-float-in-range': '2.454',
        'random-boolean': 'true',
        'random-boolean-nullable': 'true',
        'random-type': 'sort',
        'random-unique-identifier': '7ee30678f4f54dca9f47862efd0f5c55',
        'random-id': '14859',
        'random-name-from-iterable': 'including',
        'random-name-from-function': 'kid'
    },
    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=8912,
    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=8912,
    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=1&random-values-by-iterable=foo&random-values-by-function=1&random-values-by-function-path=1&random-value-by-faker-provider-function-path=Designer%2C+television%2Ffilm+set&random-string=involve&random-integer=-35820&random-integer-in-range=2&random-float=52337.46300132734&random-rounded-float-in-range=2.454&random-boolean=true&random-boolean-nullable=true&random-type=throw&random-unique-identifier=4407ddfb4c0d43b19577e9e795c78ec9&random-id=14859&random-name-from-iterable=measure&random-name-from-function=total' \
    -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=8912,
    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=1&random-values-by-iterable=foo&random-values-by-function=1&random-values-by-function-path=1&random-value-by-faker-provider-function-path=Accommodation+manager&random-string=summer&random-integer=-35820&random-integer-in-range=2&random-float=52337.46300132734&random-rounded-float-in-range=2.454&random-boolean=true&random-boolean-nullable=true&random-type=your&random-unique-identifier=964d07fb292147a6b016e3c75f536a36&random-id=14859&random-name-from-iterable=around&random-name-from-function=hand' \
    -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=8912,
    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 '[email protected]/tmp/foo.txt' \
    -F '[email protected]/control/capital.ppt' \
    -F '[email protected]/tmp/bar.csv' \
    -F '[email protected]/tmp/bar.json' \
    -F '[email protected]/owner/design.css' \
    -F '[email protected]/soon/rather.flac' \
    -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=8912,
    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=1&random-values-by-iterable=foo&random-values-by-function=1&random-values-by-function-path=1&random-value-by-faker-provider-function-path=Fast+food+restaurant+manager&random-string=site&random-integer=-35820&random-integer-in-range=2&random-float=52337.46300132734&random-rounded-float-in-range=2.454&random-boolean=true&random-boolean-nullable=true&random-type=attention&random-unique-identifier=fb74bc922a3e4d799ef2670af49705e1&random-id=14859&random-name-from-iterable=his&random-name-from-function=Mr' \
    -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=8912,
    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