Files
2025-04-09 21:36:51 +02:00

17 lines
635 B
Perl

# Automatically enables "strict", "warnings", "utf8" and Perl 5.10 features
use Mojolicious::Lite;
use Data::Printer;
# Route with placeholder
get '/geturl/:part' => sub {
my $c = shift;
my $foo = $c->param('part');
my $ua = Mojo::UserAgent->new;
#https://octopart.com/api/v3/parts/match?apikey=ef1fc0fdda35d72b36ea&queries=[{"mpn":"LMK105BJ104KV-F"}]
my $url = $ua->get( 'https://octopart.com/api/v3/parts/match?apikey=ef1fc0fdda35d72b36ea&queries=[{"mpn":"'.$foo.'"}]' )->result->json;
$c->redirect_to($url->{results}[0]->{items}[0]->{octopart_url});
};
# Start the Mojolicious command system
app->start;