I am creating a RESTful web service using Catalyst :: Controller :: REST . I usually use Test :: WWW :: Mechanize for web testing, but this seems more suitable for testing GET / POST HTML RPC. Are there any test modules that will test HTTP with basic auth using GET / POST / PUT / DELETE etc. And JSON? maybe something that integrates well with Catalyst / PSGI, so I don't need to start a web server?
Catalyst :: Test is a subclass of LWP :: UserAgent. The following is the correct idea:
#!/usr/bin/env perl use warnings; use strict; use Test::More; use Catalyst::Test 'MyApp'; use HTTP::Request::Common; use JSON::Any; # or whatever json module you usually use my $data = 'some_json_data_here'; my $res = request( POST '/some_path', Content_Type => 'text/xml', Content => $data, ); my $content = json_decode($res->content); # or whatever, can't remember the interface. my $expected = "some_data"; is_deeply ( $content, $expected);
Or in a more modern language:
my $data = '{"username":"xyz","password":"xyz"}'; my $res = request ( POST '/bar/thing', Content_Type => 'application/json', Content => $data, );
;)
Source: https://habr.com/ru/post/902609/More articles:Why should you avoid System.exit ()? - javaC # containers - vector ,. list, queue, stack, etc. - stackMagento - How do I get a list of all allowed countries in optionsarray? - magentoHow to calculate the logarithm of 1 minus the exponent of a given small number in python - pythonASP.NET MVC Hidden Date Format - asp.net-mvcInitial installation / start of Django ... Errno 10013? - djangoWhy does a WPF application in a virtual machine work better than one direct in the OS? - virtual-machineWhy does the .NET.NET WPF application have much better user interface performance on the VMWare guest guest? - .netwhy boost :: call_traits :: param_type is "const double &" and not "double" - c ++Android: Sign in with Twitter4J - androidAll Articles