Test::Shodo::JSONRPC - Test module using Shodo for JSON-RPC Web API
use Test::More; use Plack::Test; use HTTP::Request; use JSON qw/to_json/; use Test::Shodo::JSONRPC; # PSGI application my $app = sub { my $data = { jsonrpc => '2.0', result => { entries => [ { title => 'Hello', body => 'This is an example.' } ] }, id => 1 }; my $json = to_json($data); return [ 200, [ 'Content-Type' => 'application/json' ], [$json] ]; }; # use Plack::Test my $plack_test = Plack::Test->create($app); shodo_document_root('sample_documents'); # shodo_test, like a subtest! shodo_test 'get_entries' => sub { shodo_params( category => { isa => 'Str', documentation => 'Category of articles.' }, limit => { isa => 'Int', default => 20, optional => 1, documentation => 'Limitation numbers per page.' } ); my $data = { jsonrpc => '2.0', method => 'get_entries', params => { limit => 1, category => 'technology' } }; my $json = to_json($data); my $req = HTTP::Request->new( 'POST', '/', [ 'Content-Type' => 'application/json', 'Content-Length' => length $json ], $json ); shodo_req_ok( $req, 'Request is valid!' ); my $res = $plack_test->request($req); shodo_res_ok( $res, 200, 'Response is ok!' ); # auto sock document }; shodo_write('some_methods.md'); # Generate a markdown-formatted document. done_testing();
Shodo-based test module for JSON-RPC Web API.
Copyright (C) Yusuke Wada.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Yusuke Wada <yusuke@kamawada.com>
To install Shodo, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Shodo
CPAN shell
perl -MCPAN -e shell install Shodo
For more information on module installation, please visit the detailed CPAN module installation guide.