diff --git a/README.md b/README.md index 93bee78..3e91997 100644 --- a/README.md +++ b/README.md @@ -13,15 +13,33 @@ Download the latest release from GitHub [Releases](https://github.com/vamsiikris ## Usage Usage: -`` ./vex.phar vex [] [] [] `` +`` vex [options] [--] [] [] + `` Arguments: ``` - url The URL to which the requests should be sent - n Number of requests to be made [default: 1] - c Concurrency [default: 1] - m HTTP Method [default: "GET"] + url The URL to which the requests should be sent + n Number of requests to be made [default: 1] + c Concurrency [default: 1] +``` +Options: +``` + -m, --method[=METHOD] HTTP Method [default: "GET"] + -H, --headers[=HEADERS] Headers (multiple values allowed) + -d, --body[=BODY] Request body ``` Example : -./vex.phar vex http://127.0.0.1:8000 1000 10 +- 1000 Get requests with 10 concurrency to `http://127.0.0.1:8000` + +`./vex.phar vex http://127.0.0.1:8000 1000 10` + +- 1000 POST requests with 10 concurrency to `http://127.0.0.1:8000` with custom headers and body + +``` +./vex.phar vex http://127.0.0.1:8000 1000 10 \ +-m "POST" \ +-H "accept:application/json, text/plain, */*" \ +-H "accept-language:en-IN,en-GB;q=0.8,en-US;q=0.6,en;q=0.4" \ +-d "{\"message\": \"Hello world! Your JustAPIs instance is running correctly.\"}" +``` \ No newline at end of file diff --git a/src/Vamsi/Vex/Command/VexCommand.php b/src/Vamsi/Vex/Command/VexCommand.php index 99a4c2c..d223a53 100644 --- a/src/Vamsi/Vex/Command/VexCommand.php +++ b/src/Vamsi/Vex/Command/VexCommand.php @@ -8,6 +8,7 @@ use Symfony\Component\Console\Helper\ProgressBar; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use GuzzleHttp\TransferStats; use Symfony\Component\Console\Input\InputArgument; @@ -23,8 +24,9 @@ protected function configure() ->addArgument('url', InputArgument::REQUIRED, 'The URL to which the requests should be sent') ->addArgument('n', InputArgument::OPTIONAL, 'Number of requests to be made', 1) ->addArgument('c', InputArgument::OPTIONAL, 'Concurrency', 1) - ->addArgument('m', InputArgument::OPTIONAL, 'HTTP Method', 'GET'); - + ->addOption('method', 'm', InputOption::VALUE_OPTIONAL, 'HTTP Method', 'GET') + ->addOption('headers', 'H', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'Headers', null) + ->addOption('body', 'd', InputOption::VALUE_OPTIONAL, 'Request body', null); } protected function execute(InputInterface $input, OutputInterface $output) @@ -34,7 +36,9 @@ protected function execute(InputInterface $input, OutputInterface $output) $url = $input->getArgument('url'); $number_of_requests = $input->getArgument('n'); $concurrency = $input->getArgument('c'); - $http_method = $input->getArgument('m'); + $http_method = $input->getOption('method'); + $headers = $input->getOption('headers'); + $body = $input->getOption('body'); $output->writeln("Sending $number_of_requests requests with $concurrency Concurrency"); $client = new Client([ @@ -50,10 +54,10 @@ protected function execute(InputInterface $input, OutputInterface $output) $progress->setFormat(' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s% %memory:6s%'); $progress->start(); - $requests = function ($total) use ($url, $http_method) { + $requests = function ($total) use ($url, $http_method, $headers, $body) { $uri = $url; for ($i = 0; $i < $total; $i++) { - yield new Request($http_method, $uri); + yield new Request($http_method, $uri, $headers, $body); } };