[sf-perl] REST-API fail (POST request).

Collin Seaton collinseaton at gmail.com
Sun Nov 20 09:47:51 PST 2022


Hi William,
You can check your $response for more details on the failure. Specifically:

die "Failed: ", $response->{content}, "\n" unless $response->{success};

This is a guess, based on past work with Perl and web APIs, but you
probably need to install some modules to support the https protocol. From
the HTTP::Tiny docs, you'll need IO::Socket::SSL and Net::SSLeay.
https://metacpan.org/pod/HTTP::Tiny#SSL-SUPPORT

-collin

On Sun, Nov 20, 2022 at 7:38 AM William Michels <wjm1 at caa.columbia.edu>
wrote:

> Hello,
>
> I'm trying to get the example Perl5 code from the bottom of this REST-API
> page to work:
>
> https://rest.ensembl.org/documentation/info/archive_id_post
>
> I can get the example curl, wget, and R code to work from the same page,
> so I know the server (https://rest.ensembl.org) is up and running. Below
> is the code, cut-and-pasted. I had to install the JSON module. All I get
> back is the string "Failed!" while curl, wget, and R all return actual
> data:
>
>
> use strict;
> use warnings;
>
> use HTTP::Tiny;
>
> my $http = HTTP::Tiny->new();
>
> my $server = 'https://rest.ensembl.org';
> my $ext = '/archive/id';
> my $response = $http->request('POST', $server.$ext, {
>   headers => {
>       'Content-type' => 'application/json',
>       'Accept' => 'application/json'
>   },
>   content => '{ "id" : ["ENSG00000157764", "ENSG00000248378"] }'
> });
>
> die "Failed!\n" unless $response->{success};
>
>
> use JSON;
> use Data::Dumper;
> if(length $response->{content}) {
>   my $hash = decode_json($response->{content});
>   local $Data::Dumper::Terse = 1;
>   local $Data::Dumper::Indent = 1;
>   print Dumper $hash;
>   print "\n";
> }
>
>
>
> _______________________________________________
> SanFrancisco-pm mailing list
> SanFrancisco-pm at pm.org
> https://mail.pm.org/mailman/listinfo/sanfrancisco-pm
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/sanfrancisco-pm/attachments/20221120/fedf3349/attachment.html>


More information about the SanFrancisco-pm mailing list