#!/usr/bin/env perl

use 5.034;
use strict;
use warnings;

use Plack::Request;
use HTTP::Tiny;
use Data::Dumper qw(Dumper);
use URI;

sub {
    my $env = shift;
    my $req = Plack::Request->new($env);
    my $uri = URI->new('https://services.obvsg.at/sru/OBV-LIT/');
    $uri->query_form(
        operation   => 'searchRetrieve',
        query       => $req->param('query'),
        startRecord => $req->param('startRecord') || 0,
    );
    my $res = HTTP::Tiny->new->get( $uri->as_string );
    return [ 200, [ $res->{headers}->%* ], [ $res->{content} ] ];
};

