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='python',
    impl='requests',
    method='GET',
    url='https://github.com/mondeja/http-request-codegen',
    headers={
        'Content-Type': 'application/json',
        'Accept-Language': '*'
    },
    seed=2751,
    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': '3',
        'dinamic-value-by-function': '1',
        'random-values-by-iterable': 'baz',
        'random-values-by-function': '1',
        'random-values-by-function-path': '1',
        'random-value-by-faker-provider-function-path': ('Community education '
                                                         'officer'),
        'random-string': 'actually',
        'random-integer': '-33404',
        'random-integer-in-range': '2',
        'random-float': '39410.26432253688',
        'random-rounded-float-in-range': '2.356',
        'random-boolean': 'true',
        'random-boolean-nullable': 'null',
        'random-type': 'start',
        'random-unique-identifier': '696f470e2a794c1d8f89aa93a5eba32f',
        'random-id': '16067',
        'random-name-from-iterable': 'thing',
        'random-name-from-function': 'still'
    },
    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=2751,
    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': '3',
        'dinamic-value-by-function': '1',
        'random-values-by-iterable': 'baz',
        'random-values-by-function': '1',
        'random-values-by-function-path': '1',
        'random-value-by-faker-provider-function-path': 'Soil scientist',
        'random-string': 'can',
        'random-integer': '-33404',
        'random-integer-in-range': '2',
        'random-float': '39410.26432253688',
        'random-rounded-float-in-range': '2.356',
        'random-boolean': 'true',
        'random-boolean-nullable': 'null',
        'random-type': 'game',
        'random-unique-identifier': '8a10f05f9d2846d2911f332d054617cb',
        'random-id': '16067',
        'random-name-from-iterable': 'will',
        'random-name-from-function': 'evening'
    },
    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=2751,
    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': (
            '/kind/send.odt',
            open('/kind/send.odt', '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': (
            '/natural/able.csv',
            open('/natural/able.csv', 'rb'),
            'text/plain'
        ),
        'random-filepath-ct-header': (
            '/high/thousand.avi',
            open('/high/thousand.avi', '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=2751,
    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': '3',
        'dinamic-value-by-function': '1',
        'random-values-by-iterable': 'baz',
        'random-values-by-function': '1',
        'random-values-by-function-path': '1',
        'random-value-by-faker-provider-function-path': 'Food technologist',
        'random-string': 'wear',
        'random-integer': '-33404',
        'random-integer-in-range': '2',
        'random-float': '39410.26432253688',
        'random-rounded-float-in-range': '2.356',
        'random-boolean': 'true',
        'random-boolean-nullable': 'null',
        'random-type': 'agreement',
        'random-unique-identifier': '252d3f714d784ad9b31d1e8e2ac62641',
        'random-id': '16067',
        'random-name-from-iterable': 'gas',
        'random-name-from-function': 'first'
    },
    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=2751,
    parameters=[
        {
            'name': 'random-values-by-iterable',
            'values': ['foo', 'bar', 'baz']
        }
    ]
)
import requests

req = requests.post(
    'https://github.com/mondeja/http-request-codegen',
    data='baz',
    headers={
        'Content-Type': 'text/plain'
    }
)
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=2751,
    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=3&dinamic-value-by-function=1&random-values-by-iterable=baz&'
  + 'random-values-by-function=1&random-values-by-function-path=1&random-value'
  + '-by-faker-provider-function-path=Freight+forwarder&random-string=see&rand'
  + 'om-integer=-33404&random-integer-in-range=2&random-float=39410.2643225368'
  + '8&random-rounded-float-in-range=2.356&random-boolean=true&random-boolean-'
  + 'nullable=null&random-type=course&random-unique-identifier=44fe95a6044848c'
  + '5a07bb7cda089ed50&random-id=16067&random-name-from-iterable=art&random-na'
  + 'me-from-function=style',
  {
    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=2751,
    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': '3',
      'dinamic-value-by-function': '1',
      'random-values-by-iterable': 'baz',
      'random-values-by-function': '1',
      'random-values-by-function-path': '1',
      'random-value-by-faker-provider-function-path': 'Air cabin crew',
      'random-string': 'because',
      'random-integer': '-33404',
      'random-integer-in-range': '2',
      'random-float': '39410.26432253688',
      'random-rounded-float-in-range': '2.356',
      'random-boolean': 'true',
      'random-boolean-nullable': 'null',
      'random-type': 'sense',
      'random-unique-identifier': 'c6f758318a8f4b41867c400b452cfc18',
      'random-id': '16067',
      'random-name-from-iterable': 'trade',
      'random-name-from-function': 'place'
    }),
    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=2751,
    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('/poor/star.gif'),
  {
    filename: 'star.gif'
  }
);
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('/particular/huge.csv'),
  {
    filename: 'huge.csv',
    contentType: 'text/plain'
  }
);
formData.append(
  'random-filepath-ct-header',
  fs.createReadStream('/reason/wide.mov'),
  {
    filename: 'wide.mov',
    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=2751,
    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': '3',
      'dinamic-value-by-function': '1',
      'random-values-by-iterable': 'baz',
      'random-values-by-function': '1',
      'random-values-by-function-path': '1',
      'random-value-by-faker-provider-function-path': 'Dentist',
      'random-string': 'chance',
      'random-integer': '-33404',
      'random-integer-in-range': '2',
      'random-float': '39410.26432253688',
      'random-rounded-float-in-range': '2.356',
      'random-boolean': 'true',
      'random-boolean-nullable': 'null',
      'random-type': 'star',
      'random-unique-identifier': '3be71a0dc16948abb63afd1efcc6d43c',
      'random-id': '16067',
      'random-name-from-iterable': 'audience',
      'random-name-from-function': 'various'
    }),
    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=2751,
    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: 'baz',
    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='bash',
    impl='curl',
    method='GET',
    url='https://github.com/mondeja/http-request-codegen',
    headers={
        'Content-Type': 'application/json',
        'Accept-Language': '*'
    },
    seed=2751,
    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=3&dinamic-value-by-function=1&random-values-by-iterable=baz&random-values-by-function=1&random-values-by-function-path=1&random-value-by-faker-provider-function-path=Risk+manager&random-string=push&random-integer=-33404&random-integer-in-range=2&random-float=39410.26432253688&random-rounded-float-in-range=2.356&random-boolean=true&random-boolean-nullable=null&random-type=than&random-unique-identifier=70fd4fb5a7d346f1b81ff07dafe12ca3&random-id=16067&random-name-from-iterable=scene&random-name-from-function=wear' \
    -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=2751,
    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=3&dinamic-value-by-function=1&random-values-by-iterable=baz&random-values-by-function=1&random-values-by-function-path=1&random-value-by-faker-provider-function-path=Logistics+and+distribution+manager&random-string=run&random-integer=-33404&random-integer-in-range=2&random-float=39410.26432253688&random-rounded-float-in-range=2.356&random-boolean=true&random-boolean-nullable=null&random-type=as&random-unique-identifier=eb94b562d5574f4f815b34e805d6b7a5&random-id=16067&random-name-from-iterable=mission&random-name-from-function=southern' \
    -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=2751,
    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]/economic/bit.txt' \
    -F '[email protected]/tmp/bar.csv' \
    -F '[email protected]/tmp/bar.json' \
    -F '[email protected]/study/world.wav' \
    -F '[email protected]/owner/clear.mp4' \
    -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=2751,
    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=3&dinamic-value-by-function=1&random-values-by-iterable=baz&random-values-by-function=1&random-values-by-function-path=1&random-value-by-faker-provider-function-path=Product+designer&random-string=somebody&random-integer=-33404&random-integer-in-range=2&random-float=39410.26432253688&random-rounded-float-in-range=2.356&random-boolean=true&random-boolean-nullable=null&random-type=visit&random-unique-identifier=d32461419a4a415c8554b11d68bbc3e4&random-id=16067&random-name-from-iterable=surface&random-name-from-function=administration' \
    -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=2751,
    parameters=[
        {
            'name': 'random-values-by-iterable',
            'values': ['foo', 'bar', 'baz']
        }
    ]
)
curl \
    -X 'POST' \
    -d 'random-values-by-iterable=baz' \
    -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