Saltar a contenido

Introducción

http-request-codegen genera trozos de código de peticiones HTTP para diferentes implementaciones. Es perfecto si quieres incluir ejemplos documentando APIs. Soporta las siguientes características:

  • Aleatorización de parámetros de peticiones usando múltiples estrategias:
  • Valores aleatorios desde iterables y ejecutables.
  • Valores aleatorios según tipo de datos.
  • Valores aleatorios desde proveedores Faker.
  • Aleatorización usando semillas y localización.
  • Personalización de encabezados de peticiones.
  • Argumentos opcionales de peticiones por implementación.
  • Envoltura de línea personalizada.
  • Indentación personalizada.
  • Personalización de caracteres de cadenas.
  • Renderizado en una línea.

Recuerda

Esto no es una API de más alto nivel entre muchas bibliotecas de peticiones HTTP, pero está escrita de tal forma que puedes generar los tipos de peticiones HTTP más comunes independientemente de la implementación.

Instalación

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]

Demostración

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',
        },
    ]
)

Esta implementación emulará a la API fetch de los navegadores por defecto, usando procesamiento de respuestas mediante promesas.

Si quieres simular un entorno NodeJS, pasa el parámetro setup como True y el siguiente trozo de inicialización será colocado al principio del código generado:

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

Para simulación de importaciones ESM usa setup='import fetch from \'node-fetch\';\n\n', por lo que el código de inicialización será:

import fetch from 'node-fetch';

Por supuesto, puedes personalizar esta inicialización para otros entornos. Por ejemplo, hacer un polyfill a la API usando whatwg como módulo ESM usando 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',
        },
    ]
)

Los parámetros son pasados usando el parámetro params de la función requests.get, no añadiendo ?foo=bar&... a la URL. Si quieres este comportamiento, construye la URL pasada usando las funciones lazy_name_by_parameter y lazy_value_by_parameter en lugar de usar el argumento parameters.

Si quieres importar más módulos en el código de inicialización, ten en cuenta que debes proveer import requests en el argumento setup. Por ejemplo, setup='import requests\nimport foo\n\n' renderizará como:

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',
        },
    ]
)

Pasa opciones extra al comando 'curl' en el parámetro kwargs. Por ejemplo, para guardar la respuesta en un archivo, pasa 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

Soporte

GET POST
Encabezados
Parámetros
Localización de parámetros
Semilla de parámetros
Indentación personalizada
Personalización de caracter de cadena
Renderizado en una línea
Inicialización personalizada
Finalización personalizada
Máximo ancho de línea personalizado
GET POST
Encabezados
Parámetros
Localización de parámetros
Semilla de parámetros
Indentación personalizada
Personalización de caracter de cadena
Renderizado en una línea
Inicialización personalizada
Finalización personalizada
Máximo ancho de línea personalizado
GET POST
Encabezados
Parámetros
Localización de parámetros
Semilla de parámetros
Indentación personalizada
Personalización de caracter de cadena
Renderizado en una línea
Inicialización personalizada
Finalización personalizada
Máximo ancho de línea personalizado