Test::RestAPI - Real mock of REST API
my $api = Test::RestAPI->new( endpoints => [ Test::RestAPI::Endpoint->new( path => '/a', method => 'any', ) ], ); $api->start(); HTTP::Tiny->new->get($api->uri.'/test');
In many (test) case you need mock some REST API. One way is mock your REST-API class abstraction or HTTP client. This module provides other way - start generated Mojolicious server and provides pseudo-real your defined API.
ArrayRef of instances Test::RestAPI::Endpoint
default is / (root) 200 OK - hello:
Test::RestAPI::Endpoint->new( path => '/', method => 'any', render => {text => 'Hello'}, );
This attribute is used for generating mojo application.
default is Test::RestAPI::MojoGenerator
Start REST API (Mojolicious) application on some random unused port and wait to initialize.
For start new process is used fork-exec on non-windows machines and Win32::Process for windows machines.
fork-exec
For generating Mojolicious application is used Test::RestAPI::MojoGenerator in mojo_app_generator attribute - is possible set own generator.
mojo_app_generator
return count of request to $path endpoint
$path
return list (ArrayRef) of requests body to $path endpoint
Copyright (C) Avast Software.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Jan Seidl <seidl@avast.com>
To install Test::RestAPI, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::RestAPI
CPAN shell
perl -MCPAN -e shell install Test::RestAPI
For more information on module installation, please visit the detailed CPAN module installation guide.